hi every body can some one help me with thi problem i have a text file which is following
hi Hello this is my Hello to
the Hello world
i write a code in c which is following
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void main()
{
FILE *fp,*fout;
int i=0,len_string;
char SearchText[]="Hello"; /* You can replace this text */
char ReplaceText[]="Help"; /*You can also replace this text. */
char temp[30];
fp=fopen("ram.txt","a+");
fout=fopen("temp.txt","a+");
rewind(fp); /* for going to start of file. */
if(fp==NULL || fout==NULL)
{
printf("File couldn't be opened ");
exit(0);
}
len_string=strlen(SearchText);
while(!feof(fp))
{
for(i=0;i<len_string;i++)
{
temp[i]=fgetc(fp);
}
temp[i]='\0';
if(strcmp(SearchText,temp)==0) /* the stricmp() is used for comparing both string. */
{
fprintf(fp,"%s ",ReplaceText);
fprintf(fout,"%s",ReplaceText);
fflush(fp);
fclose(fp);
fclose(fout);
exit(1);
}
}
fclose(fp);
fclose(fout);
}
now my out put is like that
hi Hello this is my Hello to
the Hello world
Help Help what i m doing wrong ? how to replace Hello to help in my text file ? how to get my output like that?
hi Help this is my Hello to
the Help world
can anybody explain with code ?
mainisint. Also, please try to indent your code.temp.txtsupposed to do?