Reading different data from a textfile delimited with semicolons in C.

Posted by Chris_45 on Stack Overflow See other posts from Stack Overflow or by Chris_45
Published on 2009-12-01T09:34:09Z Indexed on 2010/03/13 6:55 UTC
Read the original article Hit count: 186

Filed under:
|
|
|

How do one read different records of data that are separated with semicolons into an array in C?

from textfile: Text One; 12.25; Text Two; 5; Text Three; 1.253

fopen ...
for(i = 0; i < nrRecords; i++) {
fscanf(myFile, " %[^;];", myRecords[i].firstText);  /* Ok first text*/
fscanf(myFile, "%lf", &myRecords[i].myDouble1);     /* But goes wrong with first double */
fscanf(myFile, " %[^;];", myRecords[i].secondText); 
fscanf(myFile, "%d", &myRecords[i].myInt1);     
fscanf(myFile, " %[^;];", myRecords[i].thirdText); 
fscanf(myFile, "%lf",&myRecords[i].myDouble2);    
}
fclose...

© Stack Overflow or respective owner

Related posts about c

    Related posts about input