天天看点

DOS格式的文件转成Unix格式的文件(程序实现)

#include 

main

(

argv

args

[]){char * int 

  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

[

NULL

){1],"rb"))==((

    printf

(

args

[1]);"Error: Fail to open %s.",

return 1;

}

if

argv

==2){(

sprintf

(

s

,

args

[1]);"u_%s",

}

else{

sprintf

(

s

,

args

[2]);"%s",

strcmp

(

s

,

args

[1])==0){if(

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; "stdio.h"

#include  "stdlib.h"

#include  "conio.h"

#include  "string.h"

int  }   附:如果在Unix下,只消几行语句就可以解决问题: #!/bin/sh

tr -d '/015' < "$1" >temp.$$

mv temp.$$ "$1"