diff options
author | sinanmohd <sinan@firemail.cc> | 2023-05-01 22:12:45 +0530 |
---|---|---|
committer | sinanmohd <sinan@firemail.cc> | 2023-05-01 22:13:41 +0530 |
commit | 16c2c412f3062924ad7869068730b2c56afbcff8 (patch) | |
tree | ad1dbf51430bf72064503ae0122f435b13a9fc6a /6.1.1/main.c | |
parent | c5b2cb7bfd3a59036cc3ad7088f4ca3765025f58 (diff) |
6.1.1: 6.1 but with pointers instead of array indices
Diffstat (limited to '6.1.1/main.c')
-rw-r--r-- | 6.1.1/main.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/6.1.1/main.c b/6.1.1/main.c new file mode 100644 index 0000000..3d35bb0 --- /dev/null +++ b/6.1.1/main.c @@ -0,0 +1,69 @@ +#include <stdio.h> +#include <ctype.h> +#include "word.h" +#include "key.h" + +#define MAXWORD 100 + +struct key keytab[] = { + "#define", 0, + "#elif", 0, + "#else", 0, + "#endif", 0, + "#error", 0, + "#if", 0, + "#ifdef", 0, + "#ifndef", 0, + "#include", 0, + "#pragma", 0, + "#undef", 0, + "auto", 0, + "break", 0, + "case", 0, + "char", 0, + "const", 0, + "continue", 0, + "default", 0, + "do", 0, + "double", 0, + "else", 0, + "enum", 0, + "extern", 0, + "float", 0, + "for", 0, + "goto", 0, + "if", 0, + "int", 0, + "long", 0, + "register", 0, + "return", 0, + "short", 0, + "signed", 0, + "sizeof", 0, + "static", 0, + "struct", 0, + "switch", 0, + "typedef", 0, + "union", 0, + "unsigned", 0, + "void", 0, + "volatile", 0, + "while", 0, +}; + +int main(void) +{ + char word[MAXWORD]; + struct key *p; + + while (getword(word, MAXWORD) != EOF) + if (isalpha(word[0]) || word[0] == '#') + if ((p = bsearch(word, keytab, NKEYS)) != NULL) + p->count++; + + for (p = keytab; p < keytab + NKEYS; ++p) + if(p->count > 0) + printf("%4d %s\n", p->count, p->word); + + return 0; +} |