|
Hello All,
I have been trying to write a C program to read a specific line from the header of a formatted ASCII file containing GPS data. The line is somewhat like this:
1337936.4550 6070317.1261 1427876.7852 APPROX POSITION XYZ
the problem is the position of this line is not fixed and could be different in different files, although it always remains in the header.
I have a code (which gives no result)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LEN 81
int main(void)
{
FILE *file;
int i;
char name[13], string[81], condn[20];
float x, y, z;
printf("\nEnter file name:\t");
fgets(name, 13, stdin);
if ((file = fopen(name, "r")) == NULL)
{
printf("\nError in opening file\n");
exit(1);
}
i=0;
while (strcmp(condn, "APPROX POSITION XYZ") == 0)
{
fgets(string, MAX_LEN, file);
sscanf(string, "\n%7.4f %7.4f %7.4f %s\n", &x, &y, &z, &condn);
i++;
}
printf("\n%7.4f %7.4f %7.4f\n", x, y, z);
fclose(file);
return(0);
}
I just need the three float values in the line as output.
Can anyone please help me with it??? I know only basic C program
|
|
|
|
|
|
|
// |