hi!
this is my input file by name SC.txt
CD 737 123457
AM 320 246
XY 543 357
AR 222 2
TY 212 1357
now i want to read this file and compare the last column entires with a user entered number.
i.e user enters a no. for example 2 then i need to compare this no. with last entry...which lets say is represented by dop...
here's my code
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
struct air
{
char a[3];
int b;
int dop[8];
};
struct air ia;
int da=0;
fp=fopen("SC.txt","rb");
if(fp==NULL)
{
puts("Cannot open file");
exit(0);
}
printf("Enter da: ");
scanf("%d",&da);
for(i=0;i<=50;i++)
{
while(fscanf (fp,"%s %d %d",ia.a,&ia.b,ia.dop[i]) != EOF)
{
if(da==ia.dop[i])
printf("Code %s ",ia.a);
}
}
fclose(fp);
}
But when i run this program using da=2 entered by user
it only shows output as
Code : AR
and doesn't show other codes where dop contains 2
i.e output should be
Code : CD
Code : AM
Code : AR
can anyone tell me where iam going wrong???