/* 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/sh
tr -d '\015' < "$1" >temp.$$
mv temp.$$ "$1"
评论