求助,关于文件中的查找与替换
我想将s.class中部分数据用cocn数组替换,并保存为s.class.bak文件,但总是得不到正确的运行结果,哪位大侠帮看看#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE *op;
char coru[]="@c1dd7ab77e2c967746fe10681026c920f864811321bcb8be6bbfa5a03fda4e16c9c8db3af280f7703366e778e93c55e7159a8852d2b1381e521a337f22b1406cddf41a3114aecb4f4bfe79e0c5aa2ba8824fc989cb8bdcbf8ec5cef5176bfd4059f229b91bfa025126b295f9c409e75f6f6415ee094fd7f5dfd395a1f431668c5a08e88de891dc4dd38d4e9aa9b9c00dc604a0428e3aa5a28ccfa75af099147b";
char cocn[]="@87e582b417a4bf188a8ae01c5d5f799f24ca0e65dc75a31d5f58b15baa97e96dd88001351ac2dacfce4c5bfafd13b657dcc9faa7027e83642c5931fb51153e1888dc4e897de0fa44848b86eb97e3dfcbb89e4cbe14d302b4f83b2c698b0ad772fc7b0d619f1acaf3e2cab3d20e2957953883384397a77206992189cefa6bf1b25b08663adb683bdb4ad8d9870a3be1b483d091242f0996b99b847980ac63b81b";
char seru1[]="195.189.142.68";
char secn1[]="203.91.19.12";
char seru2[]="server.
char secn2[]="cust-kong.
char soru[]="yahoo";
char socn[]="google";
char xg[150000];
long i=0,o;
void place(char num[],char s[],char r[]);
op=fopen("s.class","rb");
while(!feof(op))
{
xg[i]=fgetc(op);
i++;
}
fclose(op);
xg[i-1]='\0';
place(xg,coru,cocn);
op=fopen("s.class.bak","wb");
o=strlen(xg);
for(i=0;i<o;i++)
fputc(xg[i],op);
fclose(op);
}
void place(char num[],char s[],char r[])
{
long m,j,k,l,b,a;
char tem[500];
a=strlen(num);
m=strlen(s);
l=strlen(r);
printf("%ld,%ld,%ld",m,l,a);
for(j=0;j<a-m;j++)
{
for(k=0;k<m;k++)
tem[k]=num[j+k];
tem[k+1]='\0';
if(strcmp(tem,s)==0)
{
if(m==l)
{
for(b=0;b<l;b++)
num[b+j]=r[b];
}
else if(m>l)
{for(b=0;b<l;b++)
num[b+j]=r[b];
for(b=j+l;b<a-m+l;b++)
num[b]=num[b+m-l];
num[b]='\0';
}
else if(m<l)
{
for(b=a+l-m;b>j+l;b--)
num[b]=num[b-l+m];
num[a+l-m+1]='\0';
for(b=0;b<l;b++)
num[b+j]=r[b];}
}
}
}
s.class请从这下载users6.
[[it] 本帖最后由 kingdragonfly 于 2008-9-29 13:31 编辑 [/it]]