#include
#include
#include
int main()
{
char str[80];
int word=0, num=0,i;
scanf_s("%s", str,strlen(str));
for (i = 0;str[i] != ' /0'; i++)
if (str[i] == ' ')word = 0;
else if (word = 0) {
word = 1;
num++;
}
printf("There has %d word", num);
system("pause");
字符串结束符是'\0',不是你写的'/0'.
另外else if内的判断应该是 == 而不是 =.
其实,是我太粗心了,str[]还没输入不能用strlen函数测长度,再加上不知道scanf不能输入带空格的字符串。