Write a C program to create structure student having fields Rollno, Name. Accept the details of students from the user store it into the file and Calculate the size of File.


#include<stdio.h>
#include<conio.h>
void main()
{
  struct stud
            {
            int sno;
            float per;
            char name[20],add[20];
             }s;
  int i,n;
int size = 0;
  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);
    fprintf(fp,"%d\n%s",s.sno,s.name);
            }
  fseek(fp, 0, 2);    /* file pointer at the end of file */
  size = ftell(fp);   /* take a position of file pointer un size variable */
  printf("The size of given file is : %d\n", size);   
  fclose(fp);
  getch();
} 
/* output

Enter the stud no:->11
Enter the stud name:->asha
The size of given file is : 8    */