Creating a student data file using fread() function


#include<stdio.h>
#include<conio.h>
typedef struct
{
int dd;
int mm;
int yy;
}DATE;
typedef struct
{
char name[20];
int rno;
double fees_inst;
DATE pay_date;
}STDREC;
main()
{
      char wish;
      char fees_inst[20];
      STDREC std;
      FILE *stdfile;
      stdfile=fopen("student.dat","rb");
      getch();
      if(stdfile==0)
      {
      printf("\nError in opening.\n");
      getch();
      }
      else
      {
          system("cls");
          fread(&std,sizeof(STDREC),1,stdfile);
          while(!feof(stdfile))
          {
          printf("\nName : %s",std.name);
          getch();
          printf("\nRoll No : %d",std.rno);
          printf("\nAmt Paid : %4.2f",std.fees_inst);
          printf("\nPay Date :%d/%d/%d",std.pay_date.dd,std.pay_date.mm,std.pay_date.yy);
          fread(&std,sizeof(STDREC),1,stdfile);
          getch();
          }
      fflush(stdin);
      }fclose(stdfile);
}

Comments

Popular posts from this blog

Migrating database from ASP.NET Identity to ASP.NET Core Identity

Customize User's Profile in ASP.NET Identity System