copy.c
K&R, p. 17
download
#include <stdio.h> // for getchar(), putchar(), EOF
// copy input to output
int main()
{
int c;
while ((c = getchar()) != EOF)
{putchar(c);}
}
/*
gcc copy.c -o copy
./copy // input from the keyboard
Hello, world! // Enter
Hello, world!
Foo and bar stand for fool and bear. // Enter
Foo and bar stand for fool and bear.
-1 // read as two chars, not as EOF
-1
// Ctrl+D or Ctrl+C in Linux, Ctrl+Z then Enter in Windows (EOF)
./copy < copy.c // redirect input to file
./copy < copy.c > copy2.c // output to another file
gcc copy2.c -o copy2
./copy2
./copy2 < copy2.c
./copy < copy > copy2
./copy2 < copy2.c // still working
rm copy2 copy2.c // clean
*/
Comments
Post a Comment