I have a file that has three columns(readings from sensor) of varying length eg.
-728 -233 3947
4258 -623 333
-500 93 -4141
-491 107 -4136
-495 94 -4161
-886 101 -4148
-2555 1864 -4888
I use fgets
to read the line. But I want to read the first column as x, second as y and third as z. Even if I use blank space as the mark for detecting a new substring, that wont solve my problem, since every line has different length of column digits. Any idea on how to do it? I am pasting a snippet of the code which reads the line from file and tries to print the three substrings as three array elements.
char *arr_x, *arr_y, *arr_z;
fp = fopen(filename, mode);
while(! feof(fp))
{
if( fgets (str, 60, fp)!=NULL )
{
strncpy(arr_x, str, ' ');
strncpy(arr_y, str, ' ');
puts(str);
}
}