#include"stdlib.h"
main()
{
FILE *fp
char str[80],*p,*head
int n=0
long filelen
loop1: printf("请输入您要用于 *** 作的文件名及其完整路径:\n")
gets(str)
fp=fopen(str,"rb+")
if(fp==NULL)
{
printf("找不到指定文件,要指定新文件吗?(y=是的,要指定新文件\telse=不用了,退出程序)\t")
gets(str)
if((char)tolower((int)str[0])=='y')goto loop1
else exit(0)
}
printf("请输入您要查找并替换的字符(如果输入的字符数量大于1本程序会自动舍去多余的部分)\n")
gets(str)
printf("请输入您要将找到的字符或字符串替换为的字符(自动舍去多余部分)\n")
gets(&str[1])
fseek(fp,0L,2)
filelen=ftell(fp)
fseek(fp,0L,0)
head=(char *)malloc(filelen)
fread(head,filelen,1,fp)
for(p=headp<head+filelen/1Lp++)if(*p==str[0]){*p=str[1]n++}
fseek(fp,0L,0)
fwrite(head,filelen,1,fp)
fclose(fp)
printf("替换已经完成,共替换%d处\n",n)
}
#include "stdio.h"#include <stdlib.h>
#include <string.h>
#include "time.h"
char s[2000][1501]
int main(int argc,char *argv[]){
char t[26],f[5]="ABCD",*pt
int i,j,k,n
srand((unsigned)time(NULL))
for(i=0i<2000i++){
for(n=rand()%501+1000,j=0j<ns[i][j++]=f[rand()%4])
s[i][j]='\0'
}
for(i=0i<25t[i++]=f[rand()%4])
t[i]='\0'
printf("Looking for \'%s\'...\n",t)
for(n=j=k=i=0i<2000i++){
if((pt=strstr(s[i],t)) && strstr(pt+1,t)){
pt=NULL
n=2
break
}
if(pt && ++n==1)
k=i,j=pt-s[i]
if(n>1)
break
}
if(n==1)
printf("There is only one \'%s\', which began from s[%d][%d].\n",t,k,j)
else if(n>1)
printf("Find more...\n")
else
printf("Could not find...\n")
return 0
}
运行样例:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)