 |
我的日历 |
|
|
分类日志 |
|
|
友情链接 |
|
|
最新评论 |
|
|
搜索日志 |
|
|
访问计数 |
|
|
获取 RSS |
| |
 | |
|
struct's being used [2005-4-19] youalwayscan 发表在 C/C+基础
| Consider writing a program to count the occurrences of each C keyword. We need an array of character strings to hold the names, and an array of integers for the counts. One possibility is to use two parallel arrays, keyword and keycount, as in char *keyword[NKEYS]; int keycount[NKEYS];
But the very fact that the arrays are parallel suggests a different organization, an array of structures. Each keyword is a pair: char *word; int cout;
and there is an array of pairs. The structure declaration struct key { char *word; int count; } keytab[NKEYS];
declares a structure type key, defines an array keytab of structures of this type, and sets aside storage for them. Each element of the array is a structure. | |
|
|