慢点慢点,先把那个单词数的问题整整明白,循环里头是什么意思?呵呵

梦想拥有一台龙芯3A-4000
程序代码:#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE* fp;
char fname[40];
char cnt;
int c;
int num;
int word;
char str[10];
cnt = 0;
word = 0;
num = 0;
// 输入文件名,打开文件
printf("please enter file name:");
gets(fname);
if ((fp = fopen(fname, "r")) == NULL)
{
printf("cannot open file.\n");
exit(0);
}
while ((c = fgetc(fp)) != EOF)
{
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) // 1. 判斷是不是字母
{
if (word == 0) // 2. Word初值为0
cnt++; // 3. 單詞數加1.
}
else
continue;
}
//读取字符串,统计某个单词数目
fseek(fp,0L,0);//将文件指针移到开头
while((c=fgetc(fp))!=EOF)
{
if((c=='Y')||(c=='y'))
{
c=fgetc(fp);
if(c==EOF)
goto next;
else if((c=='E')||(c=='e'))
{
c=fgetc(fp);
if(c==EOF)
goto next;
else if((c=='S')||(c=='s'))
num++;
}
}
}
next:
//输出单词数目和“Yes”的数目
printf("There are %d words in this file.\n", cnt);
printf("There are %d Yes in this file.\n",num);
fclose(fp);
return 0;
}
不知楼主是不是这个意思,我先大致改了下,可以统计字母数量,统计yes的数量!