Here I am searching a string in text file and replacing it with new string. In this code it finds but the new word wrights at the end of the text file and not replacing. Plz. can anybody help me.....
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
FILE *fp;
int f=0,l,n=0;
char *st, *st1, *st2;
clrscr();
printf("\n\nEnter string to search:");
scanf("%s",st1);
printf("Enter text to replace:");
scanf("%s",st2);
fp=fopen("c:\\folder/file.txt","a+");
while(!feof(fp))
{
fscanf(fp,"%s",st);
if(strcmpi(st,st1)==0)
{
f=1;
n++; /*Number of time the string repeats*/
}
}
if(f==1)
fprintf(fp,"%s",st2);
fclose(fp);
getche();
}