指向结构的指针.docxVIP

  • 3
  • 0
  • 约2.08千字
  • 约 2页
  • 2023-04-30 发布于上海
  • 举报
指向结构的指针 为了进一步说明指向结构的指针和结构数组,我们重新编写关键字统计程序,这次采用指针,而不使用数组下标。 keytab的外部声明不需要修改,但main和binsearch函数必须修改。修改后的程序如下: #include stdio.h #include ctype.h #include string.h #define MAXWORD 100 int getword(char *, int); struct key *binsearch(char *, struct key *, int); /* count C keywords; pointer version */ main() { char word[MAXWORD]; struct key *p; while (getword(word, MAXWORD) != EOF) if (isalpha(word[0])) if ((p=binsearch(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; } /* binsearch: find word in tab[0]...

文档评论(0)

1亿VIP精品文档

相关文档