缺陷是,我想进行改进,却不知如何做起。
#include<stdio.h>
int main()
{
char string[81];
int i, num = 0, word = 0;
char c;
gets(string);
for (i = 0; (c = string[i]) != '\0'; i++ ) //这里检查是否是结束符 ,C中‘\0’为字符串结束符,而空格字符‘ ’表示输入字符串之间的分隔符,eg:键盘输入how are you?时候,通过执行语句scanf("%s",str);只会输出how;而使用scanf("%s%s%s",&str1,&str2,&str3);便能全部输出。
if (c ==' ') word = 0;
else if (word == 0)
{
word = 1;
num++;
}
printf("there are %d words in this line.\n", num);
return 0;
}
//替换不会