Reading a string from a file and writing it into a structure [C]
I have a text file that looks like this: Tony 98 Alex 76 Emily Rose 88 Structure that I need to load data into looks like this: struct Student{ char name[20]; int score; }array[100]; I am using fscanf for loading data into array of structures like this: while(i<100 && fscanf(input,"%20s %d",array[i].name, &array[i].score)==2) i++; I encounter a problem with "Emily Rose" since it only loads "Emily" and stops there. I know how to solve this problem if name and score are separated by something that's not a space(for example a comma): while(fscanf(filename,"%d",&niz[i].score)==1){ i=-1; do{ if(i<20) i++; name[i]=fgetc(filename); }while(name[i]!=',' && name[i]!=EOF); name[i]='\0'; } This would work if my file looked like this: 88,Emily Rose How can I make it work if there are spaces between names, and name and score?