都怪我一看到天下第一的帖就激动万分迷失本性了.没有注意到原来是在斗程序,我喜欢C,我就用C写一个.
FILE *fp0,*fp1;
int start;
int *end;
int i,size;
int index=0,count=0;
int a;
char *buffer;
char ch,ch0,ch1;
fp0=fopen("xtxdy.txt","rb");
if(fp0!=NULL)
{
fseek(fp0,0,SEEK_END);
size=ftell(fp0);
end=(int *)malloc(((size>>1)+1)*sizeof(int));
fseek(fp0,0,SEEK_SET);
for(i=0;i<size;i++)
{
fread(&ch,1,1,fp0);
ch0='\r';
ch1='\n';
for(a=0;a<2;a++)
{
if(ch==ch0)
{
if(i+1<size)
{
fread(&ch,1,1,fp0);
i++;
if(ch==ch1)
{
end[count++]=ftell(fp0);
}
break;
}
}
ch0='\n';
ch1='\r';
}
}
if(count==0 || end[count-1]!=size)
{
end[count++]=size+2;
}
fp1=fopen("temp1.txt","wb");
if(fp1!=NULL)
{
ch0='\r';
ch1='\n';
while(count>0)
{
count--;
if(count>0)
{
start=end[count-1];
}
else
{
start=0;
}
fseek(fp0,start,SEEK_SET);
buffer=(char *)malloc(end[count]-start-2);
fread(buffer,end[count]-start-2,1,fp0);
fwrite(buffer,end[count]-start-2,1,fp1);
if(count>0)
{
fwrite(&ch0,1,1,fp1);
fwrite(&ch1,1,1,fp1);
}
free(buffer);
}
fclose(fp1);
}
free(end);
fclose(fp0);
}
remove("xtxdy.txt");
rename("temp1.txt","xtxdy.txt");
代码是多了点,但这不是我的错,是C的错,C函数不够强大,
C这样做是给高级语言抹黑!C太不争器了!
