【发布时间】:2013-03-30 19:20:47
【问题描述】:
所以,我在编译 C 文件时收到了一些警告,我不知道如何修复。
第一个警告来自以下代码:
char line[100];
char* carbonCopy;
char *currentWord;
wordlist *theList = malloc(sizeof(wordlist));
theList->head->string = NULL;
word *fromFile = malloc(sizeof(word));
while(fgets(line,99,file)){
if(line != NULL){
carbonCopy = line;
while((currentWord = strsep(&line, " ")) !=NULL)
{
malloc(strlen(currentWord)*sizeof(char));
fromFile->string = currentWord;
fromFile->next = malloc(sizeof(word));
警告指出:
从不兼容的指针类型传递“strsep”的参数 1 [默认启用]
【问题讨论】:
-
这与您的问题无关,但
strlen的运行时间为 O(n),因此在循环条件下使用它通常是个坏主意。 -
尝试使用 string.h 和 stdlib.h
标签: c warnings variable-assignment declaration implicit