//This is edit mode program
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<iostream.h>
int main()
{
FILE*fp1, *fp2;
char fname[100],lname[100];
char fncomp[100],lncomp[100];
int age;
fp1 = fopen("OriginalTextFile.txt","r"){
}
fp2 = fopen("TemporaryTextFile.txt","w"){
}
printf("Enter First name of a person that you want to edit: ");
scanf("%s", &fncomp);
while(!feof(fp1)){
fscanf(fp1,"%s %s %d", fname,lname,age);
if(strcmpi(fncomp,fname)==0)
printf("%s %s %d\n\n", fname,lname,age);
printf("Replace name with: ");
scanf("%s %s",&repfname, &replname);
fname = repfname;
lname = replname;
fprintf(fp2,"%s %s %d", fname,lname,age);
}
fclose(fp1);
fclose(fp2);
fp2 = fopen("TemporaryTextFile.txt","r"){
}
fp1 = fopen("OriginalTextFile.txt","w"){
}
while(!feof(fp2))
{
fscanf(fp2,"%s %s %d", fname,lname,age);
fprintf(fp1,"%s %s %d", fname,lname,age);
}
fclose(fp1);
fclose(fp2);
getch();
}