正文

DOS格式的文件转成Unix格式的文件2007-01-26 18:34:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/elove/22838.html

分享到:

/* win2unix */#include "stdio.h"#include "stdlib.h"#include "conio.h"#include "string.h"int main(int argv, char * args[]){  FILE *fp1,*fp2;  char c;  char s[100];  if(argv<2){    printf("Usage: win2unix input-file-name [output-file-name]");    return 1;  }  if((fp1=fopen(args[1],"rb"))==NULL){    printf("Error: Fail to open %s.",args[1]);    return 1;  }  if(argv==2){    sprintf(s,"u_%s",args[1]);  }  else{   sprintf(s,"%s",args[2]);   if(strcmp(s,args[1])==0){      printf("Error: Output file name must not be same to that of the input file.");      fclose(fp1);      return 1;   }  }  fp2=fopen(s,"wb");  while(1){    c=fgetc(fp1);    if(feof(fp1)!=0){      break;    }    if(c!='\r'){      fputc(c,fp2);    }  }  fclose(fp1);  fclose(fp2);  return 0; }   附:如果在Unix下,只消几行语句就可以解决问题: #!/bin/shtr -d '\015' < "$1" >temp.$$mv temp.$$ "$1"

阅读(4503) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册