Skip to content

Commit cfe4094

Browse files
authored
Update 文本文件复制代码.c
1 parent 5597cd5 commit cfe4094

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed
Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,32 @@
1-
#
1+
//下面的程序,与 Unix 的 cp 命令类似,需要两个文件名作为参数,将第一个文件的内容复制到第二个文件。
2+
3+
//该程序涉及到main()函数传参的问题,请查看:C语言mian()函数详解
4+
5+
6+
#include <stdio.h>
7+
#include <stdlib.h>
8+
9+
int main(int argc, char * argv[]){
10+
FILE *fin, *fout;
11+
char c;
12+
13+
if (argc!=3){
14+
printf("Usage: %s filein fileout\n", argv[0]);
15+
exit(0);
16+
}
17+
if ((fin=fopen(argv[1],"r"))==NULL){
18+
perror("fopen filein");
19+
exit(0);
20+
}
21+
if ((fout=fopen(argv[2],"w"))==NULL){
22+
perror("fopen fileout");
23+
exit(0);
24+
}
25+
26+
while ((c=getc(fin))!=EOF)
27+
putc(c,fout);
28+
29+
fclose(fin);
30+
fclose(fout);
31+
return 0;
32+
}

0 commit comments

Comments
 (0)