diff options
Diffstat (limited to 'ch5/5-01_getint-fixed.c')
-rw-r--r-- | ch5/5-01_getint-fixed.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/ch5/5-01_getint-fixed.c b/ch5/5-01_getint-fixed.c index 8d53ba6..b013f20 100644 --- a/ch5/5-01_getint-fixed.c +++ b/ch5/5-01_getint-fixed.c @@ -23,6 +23,7 @@ int main() { while (getint(bar) > 0) { printf("%d\n", foo); } + printf("Contents of buffer:%s\n", buf); return 0; } @@ -38,8 +39,14 @@ int getint(int *pn) { sign = (c == '-') ? -1 : 1; if (c == '+' || c == '-') { c = getch(); + if (!isdigit(c)) { + ungetch(c); + ungetch(sign == 1 ? '+' : '-'); + return 0; + } } if (!isdigit(c)) { + ungetch(c); return 0; } for (*pn = 0; isdigit(c); c = getch()) { |