Program to read records from a file


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

struct student
{
 char name[25];
 int roll;
 char stream[25];
}
s;

main()
{
 FILE *f;
 int choice;
 clrscr();

 f=fopen("Student-records.txt","r");

 if(f==NULL)
 {
  printf("Cannot open the file");
  getch();
  exit(0);
 }

while(fscanf(f,"%s%d%s",s.name,&s.roll,s.stream)!=EOF)
{
 printf("\nName: %s",s.name);

 printf("\nRoll no.: %d",s.roll);

 printf("\nStream: %s",s.stream);
}


 fclose(f);
 getch();
}


0 comments:

Post a Comment