Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Search Record From Text File
- #include<conio.h>
- #include<stdio.h>
- typedef struct student
- {
- int roll, mark;
- char name;
- }stud;
- void main()
- {
- stud stud;
- FILE *fp;
- int found = 0, find;
- clrscr();
- fp=fopen("Student.txt","r");
- if(fp==NULL)
- {
- printf("\n File Opening Error");
- //exit(1);
- }
- printf("\n Enter The Roll : ");
- scanf("%d",&find);
- while(1)
- {
- fscanf(fp,"%d\t%s\t%d\n", &stud.roll, stud.name, &stud.mark);
- if(stud.roll==find)
- {
- found = 1;
- printf("\n Details Found");
- printf("\n Roll : %d", stud.roll);
- printf("\n Name : %s", stud.name);
- printf("\n Marks : %d", stud.mark);
- }
- if(feof(fp))
- {
- break;
- }
- }
- if(found==0)
- {
- printf("\n Details Not Found");
- }
- fclose(fp);
- getch();
- }
Add Comment
Please, Sign In to add comment