Hello,
I'm trying to read lines from a file and strtok it into a double array to work with the numbers.
The numbers are separated by ',' and I'm trying to fill array (line[]) with these numbers.
This is part of the code.
while(1)
{
//we will scan all the lines in the file
fscanf(separators_f, "%s", data);
if(feof(separators_f))
{
break;
}
i=0;
num=strtok(data, SEPARATOR);
//line will contain the numbers without the separators
while(num!=NULL)
{
printf("\n num is:%s\n", num);
line[i]=atof(num);
num=strtok(NULL, SEPARATOR);
i++;
}
printf("\n%f %f\n", line[0], line[1]);
my file contains:
a.txt:
2,4
1.2,-2
for some reason, in the first line, line[0] always contains 0 !
but the second line works fine and I get the real results.. now if the text file contains an empty line in the beginning, everything works fine!
CAN SOMEONE HELP PLEASE?