Program to Insert records in a file


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

struct student
{
 char name[25];
 int roll;
 char stream[25];
}
s;

main()
{
 FILE *f;
 int choice;
 clrscr();

 f=fopen("Filename.extension","a");

 if(f==NULL)
 {
  printf("Cannot open the file");
  getch();
  exit(0);
 }

do
{
 printf("\nEnter name: ");
 scanf("%s",s.name);
 fprintf(f,"%s",s.name);
 fprintf(f,"\n");

 printf("\nEnter Roll no.: ");
 scanf("%d",&s.roll);
 fprintf(f,"%d",s.roll);
 fprintf(f,"\n");

 printf("\nEnter Stream: ");
 scanf("%s",s.stream);
 fprintf(f,"%s",s.stream);
 fprintf(f,"\n");

 printf("Press 1 to continue ");
 scanf("%d",&choice);
}
while(choice==1);


 fclose(f);
 getch();
}


0 comments:

Post a Comment