slip no : 12_2 store the records of students in a file using structure */


struct student
int stud_no;
char stud_name[20],stud_addr[20]; float stud_per;


int main()
char file[30]; FILE *fp;

//                  printf("Enter file name : ");
//                  scanf("%s",file);

fp=fopen("file.txt","w"); if(fp == NULL)
printf("unable to open file"); exit(0);
printf("enter student roll no"); scanf("%d",&stud.stud_no);

printf("enter student name"); scanf("%s",stud.stud_name);

printf("enter student address"); scanf("%s",stud.stud_addr);

printf("enter student percentage"); scanf("%f",&stud.stud_per);
fprintf(fp,"\nNo : %d\nName: %s \nAddress=%s \nPercentge%f \n",stud.stud_no,stud.stud_name,stud.stud_addr,stud.stud_per);
//           fwrite(&stud,sizeof(stud),1,fp);


printf("records are successfully inserted");


No comments:

Post a Comment