Error: Assignment makes pointer from Integer without a cast... in C Prog -
i error whenever run program " assignment makes pointer integer without cast". code written below.... please help... thankx
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 student list directory. wait 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 error appears ctr=0; while(token != null){ strcpy(number[ctr], linebuffer); token = strtok(null, delims); //this 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); }
you haven't (at least, not in pasted code) #include
d header defines strtok
function. in c, functions haven't been prototyped yet assumed return int
. thus, we're assigning int
(function result) char*
(the type of token
) without cast.
we don't want cast, of course. want #include
header, compiler understands strtok
returns.
but don't want use strtok
if there's else job. has numerous limitations aren't obvious. robust string parsing, try sscanf
.
Comments
Post a Comment