有一篇长篇小说(假设段落开头没空格)现在要求每5段合成一段。例如有十段
1
2
3
4
5
6
7
8
9
0
合并后就是
12345
67890
1
2
3
4
5
6
7
8
9
0
合并后就是
12345
67890
#include <stdio.h>
int main(int argc, char *argv[])
{
char S_FileName[80],T_FileName[80];
char c;
FILE *s,*t;
int count=0;
printf("input SRC File Name :\n");
scanf("%s",S_FileName);
printf("input TAR File Name :\n");
scanf("%s",T_FileName);
s=fopen(S_FileName,"rb");
if(s==NULL)
{
printf("Open SRC File Error\n");
return 0;
}
t=fopen(T_FileName,"wb");
if(s==NULL)
{
printf("Open TAR File Error\n");
return 0;
}
while((c=getc(s))!=EOF)
{
if(c!='\r')//判断是不是'\r'
{
putc(c,t);
}
else
{
count+=1;
if(count==5)
{
putc(c,t);//写入'\r'
c=getc(s);
putc(c,t);//写入'\n'
count=0;
}
else
{
c=getc(s);//把'\n'吃掉。
}
}
}
fclose(s);
fclose(t);
return 0;
}
0A和0D 在ASCII里面代表什么
0a------换行符号------"\n"
0d------回车符号------"\r"
一般在windows系统中两个连用,"\r\n"------0d0a