- #include <stdio.h>
-
- int main()
- {
- char str[100];
- int count;
- fgets(str, sizeof(str), stdin);//从标准输入中读取数据
-
- count = (str[0] != ' ') ? 1 : 0;//如果第一个字符非空,则count起始值为1
- for (int i = 1; str[i] != '\0'; i++)
- {
- if ((str[i] == ' ') ? 1 : 0)//如果字符为空格,则if内语句值为1,if为真,count自增
- count++;
- }
-
- printf("%d", count);
- return 0;
- }
-
(顺手点个赞再走?虽然不知道赞有啥用。。)