Im trying to edit some code that reads in columns from a txt file to be able to read in from a csv file. The main problem I'm having is that the data in the txt files was stored as: 1 2 3 4. In the csv files the data looks like: "1","2","3","4". I'll include my current code (works for txt) below. Is it easier to edit my current code or just start over?
ifstream fin;
fin.open("filepath");
char temp[200];
while(!fin.eof())
{
fin.getline(temp,200);
if(sscanf(temp,"%f %f %f %*f\n",&var1,&var2,&var3)!=3)
{
continue;
}
printf("%f %f %f \n",var1,var2,var3);
}
No you don't have to change your code. Change your scanf function to
if(sscanf(temp, "\"%f\", \"%f\", \"%f\", \"%*f\"\n",,&var1,&var2,&var3)!=3)
to match the new format and it should work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.