From 44f89f8ad5aedfe555914478fda28807de85c9cc Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Wed, 19 Oct 2022 07:12:57 -0400 Subject: [PATCH] Some issues Something is not right. The program isn't working as it should. It does not print the occurences of keywords and isn't recognizing the EOF key. Need to figure out why this is not being allowed --- ch_06/exercise_06-01/main.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ch_06/exercise_06-01/main.c b/ch_06/exercise_06-01/main.c index e2c0e33..15553cc 100644 --- a/ch_06/exercise_06-01/main.c +++ b/ch_06/exercise_06-01/main.c @@ -12,8 +12,8 @@ #include #include -#define BUFFSIZE 100 -#define MAXWORD 100 +#define BUFFSIZE 5 +#define MAXWORD 5 #define NKEYS (sizeof keytab / sizeof(struct key)) @@ -52,11 +52,12 @@ void ungetch(int c); int getword(char *word, int lim) { - int c, getch(void); - void ungetch(int); + int c; + /* int c, getch(void); */ + /* void ungetch(int); */ char *w = word; - while (isspace(c = getch())); + while (isspace(c = getch()) || c != EOF); if (c != EOF) *w++ = c; @@ -99,7 +100,6 @@ int getch(void) { } -/* push character back on input */ void ungetch(int c) { if (bufp >= BUFFSIZE) printf("ungetch: too many characters\n"); @@ -116,10 +116,10 @@ int main() while (getword(word, MAXWORD) != EOF) if (isalpha(word[0])) - if ((p = binsearch(word, keytab, NKEYS)) >= 0) + if ((p = binsearch(word, keytab, NKEYS)) != NULL) p->count++; - for (p = 0; p < keytab + NKEYS; p++) + for (p = keytab; p < keytab + NKEYS; p++) if (p->count > 0) printf("%4d %s\n", p->count, p->word);