Hello All,
I have very basic knowledge of C and I'm trying to write a program to read a single line from an ASCII data file which has following format
" 1337936.4550 6070317.1261 1427876.7852 APPROX POSITION XYZ"
The problem is the position of line is not fixed. Its different in different files. I know the code is not correct, but this is what I could write
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char name, string[20], *chek = "APPROX";
float x, y, z;
printf("\nEnter file name:\t");
scanf("%s", &name);
FILE *file;
file = fopen(name, "r");
while (string!=chek)
{
fscanf(file, "%0.4f %0.4f %0.4f %s", &x, &y, &z, &string);
if(string==chek)
{
printf("\n%f %f %f %s\t", x, y, z, string);
}
else printf("\nLife Sux");
}
fclose(file);
}
Now when I compile it in Unix I get
1readtest.c: In function `main':
1readtest.c:17: warning: passing arg 1 of `fopen' makes pointer from integer without a cast
If I run it anyway, I get "Segmentation Fault"
Please help me. I'm very much frustrated and don't want to end up quitting C.