I want to read data from a file and parse it into a linked list.But after i had coded the program, it got few erros that i can figure it out. Anyone here can help me for that?
Thanks!
This are the data from the file:
0602R00001,Alex Zhu,12.5,20.5,35,68,CR
0602R12345,Bobby Brain,14.5,24.5,59.5,98.5,HD
0602R98765,Charles Laz,7,0,0,0,F
0602R87654,Daniel Dun,8
0602R22222,Eyvonne Young,10
Part of my code that reading the file and parse the data
After i compile, it occurs 4 erros. (bold line in my code)Code:typedef struct studentNode { char id[ID_MAX + 1]; char name[NAME_MAX + 1]; float mark[MARK_MAX]; char grade[GRADE_MAX + 1]; struct studentNode* nextStudent; } StudentNode; typedef struct studentList { Components comp[MARK_MAX - 1]; StudentNode* head; } ClassList; /******************************************************* * Parse each line in student data file into student node ********************************************************/ int parseText(char * buf, StudentNode * temp){ int i; buf = strtok(buf, ","); for(i=0; buf != NULL; i++) { if(i==0)temp->id = buf; if(i==1)temp->name = buf; if(i>1 && i<6)temp->mark[i-2] = buf; if(i==6)temp->grade = buf; } temp->nextStudent = NULL; return 0; } /************************************************************************************ * Function loadstudent() is used to load the student data file, and parse the file to linked list *************************************************************************************/ void loadStudent(ClassList* student, char* fileName){ FILE *fp; StudentNode *head; StudentNode *temp = NULL; StudentNode *next = NULL; char buf[50] = ""; int record = 0; fileName = strcat(fileName, ".mrk.dat"); if( (fp = fopen(fileName, "r")) != NULL) { printf("\nFile Found."); fp = fopen(fileName, "r"); head = (StudentNode *) malloc (sizeof (StudentNode)); temp = (StudentNode *) malloc (sizeof ( StudentNode)); next = (StudentNode *) malloc (sizeof ( StudentNode)); if ((fread (buf, 50, 1, fp)) == 0) { fclose(fp); head = NULL; } record++; parseText(buf, head); temp = head; while (fread (buf, 50, 1, fp) != 0) { printf("%s", temp->id); parseText(buf, next); temp->nextStudent = next; record++; } temp->nextStudent = NULL; if(record == 0) { printf("Database Empty"); } else printf("\nContains %d record.", record); } else { printf("\nFile Not Found.\n"); exit(1); } }
assign2.c:192: incompatible types in assignment
assign2.c:193: incompatible types in assignment
assign2.c:194: incompatible types in assignment
assign2.c:195: incompatible types in assignment



LinkBack URL
About LinkBacks



