ch1-Copy input to output

Chapter_1     Exercise_1-5     #define_directive Exercise_1-6







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
*/









Chapter_1     Exercise_1-5     #define_directive BACK_TO_TOP Exercise_1-6



Comments

Popular posts from this blog

Contents

Blogger Page Margins in Contempo