这道练习题训练了:
1.结构体数组
2.二分查找
3.指针操作
----
都不难。但非常基础,我认为非常好,做完了记到博客上来,题目见k&R,实现例如以下:
/* * Practice of struct array. K&R 6-1 * @author : wusuopubupt * @date : 2014-09-18 */ #include <stdio.h> #include <ctype.h> #include <string.h> #define MAXWORD 100 typedef struct key_{ char *word; int count; } key; key key_tab[] = { {"auto", 0}, {"break", 0}, {"case", 0}, {"char", 0}, {"const", 0}, {"continue", 0}, {"default", 0}, {"for", 0}, {"int", 0}, {"void", 0}, {"while", 0} }; int getword(char *word, int n); int binary_search(key key_tab[], char *word, int n); key *binary_search2(key *key_tab, char *word, int n); int getword(char *word, int n) { int c; char *w = word; while(isspace(c = getchar())) { ; } if(c != EOF) { *w++ = c; } if(!isalpha(c)) { *w = '