错误:赋值在C Prog中从Integer发出没有强制转换的指针

每当我运行程序“Assignment在没有强制转换的情况下从Integer发出指针”时,我都会收到此错误。 我的代码写在下面….请帮助…谢谢

struct student { char studentID[6]; char name[31]; char course [6]; }; struct student *array[MAX]; struct student dummy; int recordCtr=0; int read(){ FILE *stream = NULL; int ctr; char linebuffer[45]; char delims[]=", "; char *number[3]; char *token = NULL; stream = fopen("student.txt", "rt"); if (stream == NULL) stream = fopen("student.txt", "wt"); else { printf("\nReading the student list directory. Wait a moment please..."); while(!feof(stream)){ array[recordCtr]=(struct student*)malloc(sizeof(struct student)); while(!feof(stream)) { fgets(linebuffer, 46, stream); token = strtok(linebuffer, delims); //This is where the error appears ctr=0; while(token != NULL){ strcpy(number[ctr], linebuffer); token = strtok(NULL, delims); //This is where the error appears ctr++; } strcpy(array[recordCtr] -> studentID,number[0]); strcpy(array[recordCtr] -> name,number[1]); strcpy(array[recordCtr] -> course,number[2]); } recordCtr++; } recordCtr--; fclose(stream); } 

你没有(至少不在粘贴的代码中) #include d定义strtok函数的头。 在C中,假定尚未原型化的函数返回int 。 因此,我们在没有强制转换的情况下从int (函数结果)赋值给char*token的类型)。

当然,我们不想要演员表演。 我们想#include头,以便编译器理解strtok返回的内容。

但是,如果有其他任何可以完成工作的话,我们也不想真正使用strtok 。 它有许多不明显的限制。 要进行健壮的字符串解析,请尝试使用sscanf

我想你的char *number[3]; 应该是char number[3]; ,或者至少你应该为3个number指针中的每一个分配空间。