codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Need help with file I/O  kamathmahendra at 18:05 on Monday, January 28, 2008
 

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










CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  how to create a forum in asp.net
•  how to create a forum in asp.net
•  how to create a forum in asp.net
•  Re: facing problem in enabling a check box
•  div with position absolute?
•  Need help with file I/O
•  Re: Frusturating loop
•  reading from mic
•  getting hash from a hash of hashes


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2008