Virajsinh

FileHandling_8_Display

Nov 29th, 2017
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. //Display Record From Text File
  2.  
  3. #include<conio.h>
  4. #include<stdio.h>
  5.  
  6. typedef struct student
  7. {
  8.     int roll, mark;
  9.     char name;
  10. }stud;
  11.  
  12. void main()
  13. {
  14.     stud stud;
  15.     FILE *fp;
  16.     //int found = 0, find;
  17.  
  18.     clrscr();
  19.     fp=fopen("stud1.txt","r");
  20.  
  21.     if(fp==NULL)
  22.     {
  23.         printf("\n File Opening Error");
  24.         //exit(1);
  25.     }
  26.  
  27.     while(1)
  28.     {
  29.         fscanf(fp,"%d\t%s\t%d\n", &stud.roll, stud.name, &stud.mark);
  30.        
  31.         //if(stud.roll==find)
  32.         //{
  33.             //found = 1;
  34.             printf("\n Details Found");
  35.             printf("\n Roll : %d", stud.roll);
  36.             printf("\n Name : %s", stud.name);
  37.             printf("\n Marks : %d", stud.mark);        
  38.         //}
  39.         if(feof(fp))
  40.         {
  41.             break;
  42.         }
  43.     }  
  44.     fclose(fp);
  45.     getch();
  46. }
Add Comment
Please, Sign In to add comment