next up previous
Next: Character Counting Up: Character Input and Output Previous: Character Input and Output

File Copying

#include <stdio.h>

/* copy input to output; 1st version */
main()
{
  int c;

  c = getchar();
  while (c != EOF) {
    putchar(c);
    c = getchar();
  }
}
$\bullet$
Concepts: Text streams; getchar() & putchar()
#include <stdio.h>

/* copy input to output; 2nd version */
main()
{
  int c;

  while ((c = getchar()) != EOF)
    putchar(c);
}
$\bullet$
Concepts: Assignments in expressions


Massimo Ricotti 2009-01-26