怎样在emacs中进行多文件字符串查找替换

怎样在emacs中进行多文件字符串查找替换,第1张

你好,你的代码已经改好了,问题不大,都是一些细节。

已经编译运行确认:)

#include<stdio.h>

#include<conio.h>

#include<string.h>

#include<stdlib.h>

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()

}

如果觉得还行,请加分哦:)

macos环境:一般在/Users/[你的登录用户名]/.emacs。也可以通过"~/.emacs"路径找到该文件。

linux环境:在"/home/[你目前登录用户名]/.emacs",同样可以通过"~/.emacs"路径找到该文件。

总结,一般都是在,登录用户文件夹中的。

如果以上目录,没有找到文件,就要自己建一个这样的文件了。

亲,

注意哦,该文件是隐藏文件,如果要找到它,即得设置隐藏文件可见哦!

如果不想设置可以用“vi ~/.emacs”命令打开编辑它。或用其他的工具打开也可以哦!

如有问题,请留言!

Linux下的emacs,一般是在HOME下的

在linux中,home在路径中可以用~来代替,比如cd ~ 就会到达你目前用户所在的home下,在其中,emacs可是是隐藏的文件需要使用A参数来ls


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/11686058.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存