Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Delete Record From Text
- #include<conio.h>
- #include<stdio.h>
- typedef struct student
- {
- int roll, mark;
- char name[80];
- }stud;
- void main()
- {
- stud stud;
- FILE *fp1, *fp2;
- int found = 0, find;
- clrscr();
- fp1=fopen("stud1.txt","r");
- if(fp1==NULL)
- {
- printf("\n File Opening Error");
- //exit(1);
- }
- fp2=fopen("temp.txt","w");
- if(fp2==NULL)
- {
- printf("\n File Creating Error");
- //exit(1);
- }
- printf("\n Enter The Roll : ");
- scanf("%d",&find);
- while(1)
- {
- fscanf(fp1,"%d\t%s\t%d\n", &stud.roll, stud.name, &stud.mark);
- if(stud.roll==find)
- {
- found = 1;
- printf("\n Details Found");
- printf("\n Roll : %d", stud.roll);
- printf("\n Name : %s", stud.name);
- printf("\n Marks : %d", stud.mark);
- }
- else
- {
- fprintf(fp2,"%d\t%s\t%d\n", stud.roll, stud.name, stud.mark);
- }
- if(feof(fp1))
- {
- break;
- }
- }
- fclose(fp1);
- fclose(fp2);
- remove("stud1.txt");
- rename("temp.txt","stud1.txt");
- if(found==0)
- {
- printf("\n Record %d Not Found", find);
- }
- printf("Record Updated");
- getch();
- }
Add Comment
Please, Sign In to add comment