Skip to content

Commit 87520b5

Browse files
committed
copy from command line args
1 parent 8e2f2ee commit 87520b5

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

prog.17.1.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Program to copy on file to another -- version 2
2+
3+
#include <stdio.h>
4+
5+
int main (int argc, char *argv[])
6+
{
7+
FILE *in, *out;
8+
int c;
9+
10+
if ( argc != 3 ) {
11+
fprintf (stderr, "Need two file names\n");
12+
return 1;
13+
}
14+
15+
if ( (in = fopen (argv[1], "r")) == NULL ) {
16+
fprintf (stderr, "Can't read %s.\n", argv[1]);
17+
return 2;
18+
}
19+
20+
if ( (out = fopen (argv[2], "w")) == NULL ) {
21+
fprintf (stderr, "Can't write %s.\n", argv[2]);
22+
return 3;
23+
}
24+
25+
while ( (c = getc (in)) != EOF ) {
26+
putc (c, out);
27+
}
28+
29+
printf ("File has been copied.\n");
30+
31+
fclose (in);
32+
fclose (out);
33+
34+
return 0;
35+
}

0 commit comments

Comments
 (0)