没有stdbool.h, 我只有这样编, 但是。。。
#include<stdio.h>int main(void)
{
char text1[]="I'm a big man. ";
char text2[]="in this little. ";
int countWords(char string[]);
printf("%s-wordsnumber=%i\n", text1, countWords(text1) );
printf("%s-wordsnumber=%i\n", text2, countWords(text2) );
return 0;
}
int alphabetic(char c)
{
if( (c>='a' && c<='z')||(c>='A' && c<='Z') )
return 1;
else return 0;
}
int countWords(char string[])
{
int alphabetic(char c), i, wordcount=0,
lookingforword=1;
for(i=0; string[i]!='\0'; i++)
{
if(alphabetic(string[i]) )
{
if(lookingforword=1)
{
wordcount++;
lookingforword=0;
}else lookingforword=0;
}else lookingforword=1;
}
return wordcount;
}
到i=6的时候, lookingforword=0了,i=7的时候, 电脑又跟我把它还原成1,
不知道如何是好啊!