Hi!
I have written a C program that takes a file with 4 columns of data as input: X Y T V and do some coordinate transformation on the X, Ys.
In the program I read the data as follows
// get the entire line
fin2.getline(line,sizeof(line));
strcpy(line1,line);
data1=strtok(line, " ");
data2=strtok(NULL, " ");
data3=strtok(NULL, " ");
data4=strtok(NULL, " ");
data5=strtok(NULL, " ");
// check if line starts with # or blank line then just write it out
if (data1==NULL)
{
// case blank line
fprintf(fout,"%s\n"," ");
} else if (data1[0]=='#') {
// writing data out
fprintf(fout,"%s\n",line1);
} else {
do the processing....
Because I have some blank lines and some lines starting with # I have to copy them to the output file
The processing I do is only on the X Y so the first two columns always, the T and V columns are being copied to the output file
Finally my question is how can I make a general program that will read a file with any number of columns (3,4,5..)
without the user specifying them,capture the X, Y and do processing on them with function(X,Y) and then merely copy the other columns straight to the output with the same format
Many thanks
I have written a C program that takes a file with 4 columns of data as input: X Y T V and do some coordinate transformation on the X, Ys.
In the program I read the data as follows
// get the entire line
fin2.getline(line,sizeof(line));
strcpy(line1,line);
data1=strtok(line, " ");
data2=strtok(NULL, " ");
data3=strtok(NULL, " ");
data4=strtok(NULL, " ");
data5=strtok(NULL, " ");
// check if line starts with # or blank line then just write it out
if (data1==NULL)
{
// case blank line
fprintf(fout,"%s\n"," ");
} else if (data1[0]=='#') {
// writing data out
fprintf(fout,"%s\n",line1);
} else {
do the processing....
Because I have some blank lines and some lines starting with # I have to copy them to the output file
The processing I do is only on the X Y so the first two columns always, the T and V columns are being copied to the output file
Finally my question is how can I make a general program that will read a file with any number of columns (3,4,5..)
without the user specifying them,capture the X, Y and do processing on them with function(X,Y) and then merely copy the other columns straight to the output with the same format
Many thanks