喜逢身体 可以有一个人帮助我与THI问题 我有这是继C文件处理问题
hi Hello this is my Hello to
the Hello world
这是继
#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);
}
一个文本文件,我用C编写代码
现在我出来放就是这样
hi Hello this is my Hello to
the Hello world
帮助帮助 我做错了什么? 如何替换你好,以帮助我的文本文件? 如何获得我的输出?
hi Help this is my Hello to
the Help world
任何人都可以用代码解释吗?
main'的'返回类型'int'。另外,请尝试缩进您的代码。 – 2011-03-30 13:26:26
是为了你自己的原因缩进你的代码 – Blorgbeard 2011-03-30 13:26:54
什么是'temp.txt'应该做什么? – nmichaels 2011-03-30 13:30:36