[comp.lang.c] multiple getchar

spolsky@yale.EDU (Joel Spolsky) (09/23/88)

Are you allowed to use getchar() twice? (seems like a silly question?
read on!)

----------------------------------------------------
kangaroo% cat test.c
#include <stdio.h>

main()
{
  int c;
  c=getchar(); putchar(c);  
  c=getchar(); putchar(c);
  putchar('\n');
}
kangaroo% gcc test.c
kangaroo% echo "Hi" | a.out
H^@     
kangaroo% cc test.c
kangaroo% echo "Hi" | a.out
Hi
----------------------------------
Anybody know what's going on?

Joel Spolsky             bitnet: spolsky@yalecs     uucp: ...!yale!spolsky
Yale University          arpa:   spolsky@yale.edu   voicenet: 203-436-1483
"You can't expect to wield supreme executive power just 'cause 
some watery tart threw a sword at you!!"