0 0 15.5 15.5 -29.671 81.879 0.149821 -0.207526 0.000906136 -0.00125514 0.00154805 0
1 0 39.5 15.5 -28.7275 81.879 0.241249 -0.199974 0.0014591 -0.00120947 0.0018952 0
2 0 63.5 15.5 -27.784 83.879 0.113511 -0.208251 0.00068653 -0.00125952 0.00143448 0
3 0 87.5 15.5 -26.8405 83.879 0.262949 -0.119694 0.00159035 -0.000723924 0.00174736 0
4 0 111.5 15.5 -25.897 86.879 0.340391 -0.153879 0.00205873 -0.000930676 0.00225932 0
5 0 135.5 15.5 -24.9535 86.879 0.350416 -0.0832607 0.00211936 -0.00050357 0.00217836 0
6 0 159.5 15.5 -24.01 88.879 0.237944 -0.0505043 0.00143911 -0.000305456 0.00147117 0
7 0 183.5 15.5 -23.0665 88.879 0.416603 -0.074264 0.00251966 -0.000449157 0.00255938 0
8 0 207.5 15.5 -22.1229 89.879 0.442096 -0.140521 0.00267384 -0.00084989 0.00280567 0
9 0 231.5 15.5 -21.1794 89.879 0.599385 -0.0447657 0.00362515 -0.000270748 0.00363524 0
Above is my test.txt file, tab delimited. I would want my program to read that file, and pull a few columns to new file lets say output.txt (I haven't code that in my program yet, can ignore that first). I want to pull data from column 5, 6, and 10, and rearrange it in output.txt as column 6, 10, 5 (which is working, ignore the file output part). The problem is, I just want to pick the data from column 5 which the value equals to lets say 86.879, and the output data should look like this:
86.879 -0.000930676 -25.897
86.879 -0.00050357 -24.9535
How can I get it done? Below is my coding. Thanks in advance!
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
static const char filename[] = "test.txt";
FILE *file = fopen(filename, "r");
if ( file != NULL )
{
signed char *line[BUFSIZ];
signed char col5[BUFSIZ], col6[BUFSIZ], col10[BUFSIZ], col6x[BUFSIZ];
// remove the slashes printf("Data fetch coordinate x[mm]: ");
// remove the slashes scanf("%d", &col6x);
while ( fgets(line, sizeof line, file) != NULL )
{
if ( sscanf(line, "%*s %*s %*s %*s %s %5s %*s %*s %*s %s", &col5, &col6, &col10) == 3 )
{
if ( col6x == col6 )
{
printf("%s\t%s\t%s\n", col6, col10, col5);
}
}
}
system("pause");
}
else
{
perror(filename);
}
return 0;
}