这是我的程序(注意和6#的有点点不一样,6#的有点点笔误,第一个代码是对的):
#include <stdio.h>
#include <ctype.h>
int main()
{
char str[81];
char ap[256]={0};
int i,num=0;
for (i=0;i<26;i++)ap[i+'a']=ap[i+'A']=1;
while (gets(str)!=NULL)
{
for (num=i=0;str[i] != '\0';i++)
{
if (ap[(int)str[i]] && str[i+1]!='-' && !ap[(int)str[i+1]])
num++;
}
printf("There are %d words in the line.\n",num);
}
return 0;
}
这是测试结果:
A big one.
There are 3 words in the line.
A
big
one
.
There are 3 words in the line.
A
big
one
.
There are 3 words in the line.
A!#@$%#$big one.
There are 3 words in the line.
A big-big one.
There are 3 words in the line.
这是你的教材上的程序的测试结果:
A big one.
There are 3 words in the line.
A
big
one
.
There are 4 words in the line.
A
big
one
.
There are 4 words in the line.
A!#@$%#$big one.
There are 2 words in the line.
A big-big one.
There are 3 words in the line.