11 NOTE: getchar and ungetch work in tandem:
13 This allows the user to get a character from standard in, have a look at it
14 and then determine to use it or place it back into a buffer for later use.
16 If this buffer has any chars inside, thise will be poped off first
17 before getting more input from stdin.
24 /* reads from buffer if buffer contains chars or calls getchar otherwise */
27 return (bufp
> 0) ? buf
[--bufp
] : getchar();
30 /* places pushed-back characters into a char array shared buffer */
34 printf("ungetch: too many characters\n");
39 /* get next integer from input and put into *pn */
42 int c
, sign
, signed_num
;
44 while(isspace(c
= getch()))
46 if(!isdigit(c
) && c
!= EOF
&& c
!= '+' && c
!= '-')
52 sign
= (c
== '-') ? -1 : 1;
53 if((signed_num
= (c
== '+' || c
== '-')))
59 ungetch((sign
== -1) ? '-' : '+');
63 for(*pn
= 0; isdigit(c
); c
= getch())
64 *pn
= 10 * *pn
+ (c
- '0');
78 printf("Retval: %c\n", retval
);
81 for(i
= 0; i
< 5; i
++)