实现txt文件中的查找与替换功能

来源:百度知道 编辑:UC知道 时间:2024/06/01 13:28:25
这是个C语言编程题版本(在VC6.0上运行),请将其程序编写出来。
十万火急,大家帮帮忙,谢谢啦。

不懂hi我

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void file_replace(FILE *fp_in,FILE *fp_out,char *src,char *dst)
{
char c=fgetc(fp_in);
char tmp[100];
int count=0;
while(c!=EOF)
{
int pPos=0;
if(c!=src[pPos])
{
fputc(c,fp_out);
c=fgetc(fp_in);
continue;//如果当前字符不相等,继续下一个字符
}
memset(tmp,0,100);
while(c==src[pPos])
{
tmp[pPos]=c;
c=fgetc(fp_in);
pPos++;//相等的部分跳过
}
if(src[pPos]=='\0')
{
count++;
printf("源串已找到!替换%d处\n",count);
fputs(dst,fp_out);
continue;
}
else
{
fputs(tmp,fp_out);
continue;//如果当前字符不相等,继续下一个字符
}
}
return;
}
void main()
{
char path[100],old_path[100];
printf("请输入文件路径:\n");
gets(path);
strcpy(old