C++ Program Write a ‘C’ Program to store the records of student (stud_no, Stud_name, stud_addr, stud_Percentage) in a file using structure.


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

void main()
{
  struct stud
{
int sno;
float per;
char name[20],add[20];
}s;
  int i,n;
  char ch;
  FILE *fp;
  fp=fopen("a.txt","w");
  if(fp==NULL)
  {
  printf("\nUnable to open file!");
  }
  else
   {
    printf("\nEnter the stud no:->");
    scanf("%d",&s.sno);
    printf("\nEnter the stud name:->");
    scanf("%s",s.name);
    printf("\nEnter the stud add:->");
    scanf("%s",s.add);
    printf("\nEnter the stud per:->");
    scanf("%f",&s.per);
    fprintf(fp,"%d\n%s\n%s\n%f",s.sno,s.name,s.add,s.per);
                                                           }
     fclose(fp);
  getch();
}

/* output
Enter the stud no:->1
Enter the stud name:->amol
Enter the stud add:->baramati
Enter the stud per:->80*/