你好,你的代码已经改好了,问题不大,都是一些细节。
已经编译运行确认:)
#include
#include
#include
#include
int Count=0;
int findNum(char *str)
{
int i=0,t1=0;
FILE *p;
char ch;
if((p=fopen("image.gl","rb"))==NULL)
{
printf("\n打开文件失败\n");
exit(4);
}
while((ch=fgetc(p))!=EOF)
{
if(ch==str[t1])
t1++;
else
t1=0;
if(t1>=strlen(str))
{
printf("找到字符串%s位置为%d\n",str,i-strlen(str)+1);
Count = i-strlen(str)+1;
i=1;
break;
}
i++;
}
fclose(p);
if(!i) return 0;
return i;
}
int main(void)
{
FILE *in,*out;
char *str1="1234567";
char *str2="abcdef";
int i=0,j=0,t1=0,t2=0;
char ch;
if((t1=findNum(str1))==0)
{
printf("没有找到字符串%s\n请按任意键退出\n",str1);
return -1;
}
if((t2=findNum(str2))==0)
{
printf("没有找到字符串%s\n请按任意键退出\n",str2);
return -2;
}
if((in=fopen("image.gl","rb"))==NULL){
printf("\n打开文件失败\n");
exit(2);
}
if((out=fopen("image_new.gl","wb"))==NULL){
printf("\n创建新文件失败\n");
exit(3);
}
i=0;
/* start copy */
while((ch=getc(in))!=EOF)
{
if(t1||t2)
{
if(Count<=80)
{
if(i<=Count) fputc('0',out);
else fputc(ch,out);
}
else
{
if((i>=(Count-80))&&(i<=Count)) fputc('0',out);
else fputc(ch,out);
}
i++;
}
}
fclose(in);
fclose(out);
printf("替换完成!\n任意键关闭!\n");
getch();
}
如果觉得还行,请加分哦:)
M-x find-name-dired RET
Select root of my project
Enter *.rb as the filenames to match
Press "t" to select all files found
Press "Q" (shift Q) to start the search/replace
Enter "transaction" as the query, then enter "invoice" as the replacement.