My test file contained the following entries:
firstname1,lastname1,month1, month2 , month3 , month4firstname2,lastname2 , month1,month2 ,month3 ,month4firstname3, lastname3 ,month1, month2 , month3 , month4
Output to the console was:
firstname1,lastname1,month1,month2,month3,month4firstname2,lastname2,month1,month2,month3,month4firstname3,lastname3,month1,month2,month3,month4
FILE *pFile = fopen("test.txt","r");char szFirstName[16], szLastName[16], szMonth1[16], szMonth2[16], szMonth3[16], szMonth4[16];while(!feof(pFile)){ // scan out the fields, ignoring any whitespace and ending on a newline. fscanf(pFile," %[^, ] , %[^, ] , %[^, ] , %[^, ] , %[^, ] , %s \r\n", &szFirstName, &szLastName, &szMonth1, &szMonth2, &szMonth3, &szMonth4); // do something with the data. // I'll just dump it to the console for now. printf("%s,%s,%s,%s,%s,%s\r\n", szFirstName, szLastName, szMonth1, szMonth2, szMonth3, szMonth4);}fclose(pFile);