zero_shubham1

kuch_v

Jul 13th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.94 KB | None | 0 0
  1.         #include <stdio.h>
  2.         #include <string.h>
  3.         struct student_details{
  4.             int e_num, adm_year, marks[5][5],fees_clear;
  5.             char name[100];
  6.         };
  7.  
  8.         struct student_details sd[10];
  9.  
  10.  
  11.         void init_student(struct student_details *pt)
  12.         {
  13.             int j;
  14.             char opt;
  15.             printf("Enter name of the student: ");
  16.             gets((*pt).name);
  17.             printf("Enter enrollment no. :");
  18.             scanf("%d",&(*pt).e_num);
  19.             printf("Enter year of admission: ");
  20.             scanf("%d",&(*pt).adm_year);
  21.             for(j=0;j<5;j++)
  22.             {
  23.                 printf("Enter course(%d) code and marks obtained:",j+1);
  24.                 scanf("%d %d",&(*pt).marks[j][0],&(*pt).marks[j][1]);
  25.             }
  26.             printf("Is all the fees cleared: (Y/N)");
  27.             scanf("%c",&opt);
  28.             if(opt=='y'||opt=='Y')
  29.                 (*pt).fees_clear = 1;
  30.             else
  31.                 (*pt).fees_clear = 0;
  32.         }
  33.  
  34.         void write_dat(struct student_details *pt)
  35.         {
  36.             FILE *fp;
  37.             fp = fopen("details.dat",'ab');
  38.             const char *mytxt = ("Name:%s Enrollment no. :%d Year of admission:%d, Course code and marks obtained: %d-%d: %d-d: %d-%d: %d-%d: %d-%d , Clearance of Feed(1 is Yes|0 is No): %d",(*pt).name,(*pt).e_num,(*pt).adm_year,&(*pt).marks[0][0],&(*pt).marks[0][1],&(*pt).marks[1][0],&(*pt).marks[1][1],&(*pt).marks[2][0],&(*pt).marks[2][1],&(*pt).marks[3][0],&(*pt).marks[3][1],&(*pt).marks[4][0],&(*pt).marks[4][1],(*pt).fees_clear);
  39.             if(fp)
  40.             {
  41.                 fwrite(mytxt,sizeof(char),strlen(mytxt),fp);
  42.                 fclose(fp);
  43.             }
  44.         }
  45.  
  46.  
  47.         int main()
  48.         {
  49.             int i;
  50.             for(i=0; i<10; i++)
  51.                 init_student(&sd[i]);
  52.             for(i=0;i<10;i++)
  53.                 write_dat(&sd[i]);
  54.             return 0;
  55.         }
Add Comment
Please, Sign In to add comment