#include<stdio.h>
struct student{
int id;
char name[30];
int mark;
};
void main()
{
FILE*fp;
struct student stud;
int id_no;
fp=fopen("data.txt","r);
printf("enter id no : ");
scanf("%d",&id_no);
while(fscanf(fp,"%d %s %d",stud.id,stud.name,stud.mark)!=EOF)
{
if(id_no == stud.id)
printf("%d %[^\n] %d\n",id_no,stud.name,stud.mark);
else
printf("Error !\n");
}
fclose(fp);
}
Hello Everyone,I am stuck at the middle how to print out the certain line from the the text file..for instance when the user enter id_no 12222 ,it should print out 12222 John Brown 80
Data.txt
22333 Smith Alison 70
12222 John Brown 80
12345 Chris Ratcel 60
anyone plz help :S :S