Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //insert Data in Text File
- #include<conio.h>
- #include<stdio.h>
- typedef struct student
- {
- int roll, mark;
- char name;
- }stud;
- void main()
- {
- stud stud;
- FILE *fp;
- char ch;
- char str[999];
- clrscr();
- fp=fopen("Student.txt","a");
- if(fp==NULL)
- {
- printf("\n File Opening Error");
- }
- do
- {
- clrscr();
- printf("\n Enter Student Roll : ");
- scanf("%d",&stud.roll);
- printf("\n Enter Student Name : ");
- fflush(stdin);
- scanf("%s",stud.name);
- printf("\n Enter Student Mark : ");
- scanf("%d",&stud.mark);
- fprintf(fp,"%d\t%s\t%d\n", stud.roll, stud.name, stud.mark);
- printf("\n Enter Record [Y or N] : ");
- fflush(stdin);
- scanf("%c",&ch);
- }while (ch == 'Y' || ch== 'y');
- printf("\n Records Inserted in Text File.");
- fclose(fp);
- getch();
- fflush(stdin);
- fp=fopen("Student.txt","r");
- if(fp==NULL)
- {
- printf("\n Not Open File");
- }
- printf("\n");
- while (fgets(str,999,fp) !=NULL)
- {
- printf("%s",str);
- }
- fclose(fp);
- getch();
- }
Add Comment
Please, Sign In to add comment