dos格式,每行结束是回车换行(\r\n)
非dos格式(unix等),每行结束只是换行(\n)
C实现两种格式文件互转:
void dosToUnix()
{
char ch;
FILE *fin;
FILE *fout;
if((fin = fopen("xxxDOs.c", "rb")) == NULL)
{
printf("can't open the file/n");
return;
}
if((fout = fopen("xxxUnix.c", "wb")) == NULL)
{
printf("can't open the file/n");
return;
}
while(!feof(fin))
{
ch = fgetc(fin);
if(ch != EOF && ch!='\r')
fputc(ch, fout);
}
fclose(fin);
fclose(fout);
}
void unixToDos()
{
char ch;
FILE *fin;
FILE *fout;
if ((fin = fopen("xxxUnix.c", "rb")) == NULL)
{
printf("can't open the file/n");
return;
}
if ((fout = fopen("xxxDos.c", "wb")) == NULL)
{
printf("can't open the file/n");
return;
}
while (!feof(fin))
{
ch = fgetc(fin);
if(ch != EOF)
{
if (ch == '\n') //如果是'\n' 在之前添加一个'\r'
fputc('\r', fout);
fputc(ch, fout);
}
}
fclose(fin);
fclose(fout);
}
阅读(2371) | 评论(0) | 转发(0) |