This is a input file
DEL 0050 XYZ 0050 0310 CCU 0710
MAA 1325 TRZ 10415
KWI 0050 FJR 0325 0325 CCJ
KWI 0050 FJR 0325 0425 CCJ 0925 1005
i.e maximum items(column entries) in a row can be 8
but their data type will be in same order
i.e char int char int int char int int
i am simply trying to read it
here's my code
#include<stdio.h>
#include<string.h>
main()
{
FILE *fp;
struct air
{
char a[50];
int b;
char c[50];
int d;
int e;
char f[50];
int g;
int h;
};
struct air ia;
fp=fopen("SC.txt","rb");
if(fp==NULL)
{
puts("Cannot open file");
exit(0);
}
while(fscanf (fp,"%s %d %s %d %d %s %d %d\n",ia.a,&ia.b,ia.c,&ia.d,&ia.e,ia.f,&ia.g,&ia.h) != EOF)
{
printf("%s %d %s %d %d %s %d %d\n",ia.a,ia.b,ia.c,ia.d,ia.e,ia.f,ia.g,ia.h);
}
fclose(fp);
}
But the output contains garbage value...
it is reads the1st line till 7th column enrty but after that it prints garbage value
similarly it reads the 2nd line till 4th entry but after that it prints garbage value
but in last line it is showing the entire line...
please help me...i need to read each element in file cuz i have to use and compare these characters with some value.