int dos2unix(char * filename)
{
FILE *target;
FILE *tmpfd;
int ch;
target = fopen(filename, "r+");
if(NULL == target)
{
return -1;
}
tmpfd = tmpfile();
if(NULL == tmpfd)
{
fclose(target);
return -1;
}
while((ch = fgetc(target)) != EOF)
{
if('\r' == ch)
{
continue;
}
fputc(ch, tmpfd);
}
rewind(tmpfd);
rewind(target);
cpfile(tmpfd, target);
fclose(target);
return 0;
}
dos2unix命令的c实现
最新推荐文章于 2024-04-07 21:37:17 发布
本文介绍了一个名为 intdos2unix 的 C 语言函数,该函数用于将 DOS 格式的文本文件转换为 Unix 格式。具体实现方式是通过读取源文件并忽略回车符,然后将剩余字符写入临时文件中,最后将临时文件的内容复制回原始文件。
3301

被折叠的 条评论
为什么被折叠?



