#include <string.h>
int main(void)
{
int a = 0, b = 0, c = 0
char buf[128]
FILE *fp
/* 打开文件,文件名必须大写 */
fp= fopen("DATA5610.TXT", "r")
if (!fp) {
printf("No 'DATA5610.TXT' found.\n")
return -1
}
/* 逐次读取单词,空格或回车分割 */
while (fscanf(fp, "%s", buf) >0) {
/* 如读取到的单词是 if,则a自增 1 */
if (strcmp(buf, "if") == 0)
a++
else if (strcmp(buf, "while") == 0)
b++
else if (strcmp(buf, "for") == 0)
c++
}
printf("if: %d, while: %d, for: %d\n", a, b, c)
fclose(fp)
return 0
}
对w进行循环与字符串a比对比如"is"与a进行比对,找到a中所有有a地方然后判断该位置是否为一个单词是则在对应b中增加数字
如果代码不想自己写的话
我可以有偿代劳
main函数里面这一句为啥有个花括号??struct Node *words[26],*p}
AddWord函数里面这个地方的!=NULL也表达错了吧...
while(!=NULL){
①char str[19]
②struct Node *next
③words[i] = (struct Node*) malloc ( sizeof(struct Node) )
④( i = 0i <26i++ ) for ( p = word[i]p != NULLp = p->next ) fprintf ( "%s\t%d\n", p->data.str, p->data.freq )
⑤w[0]-'a'
⑥NewWord ( words[i], w )
⑦!strcmp ( p->data.str, w )
⑧prev->next != NULL