C语言统计单词个数:输入一行英文字符,统计单词数量
#include <stdio.h> #include <string.h>
int main() { char str[100]; int count = 0;
printf('Enter a string:');
fgets(str, sizeof(str), stdin);
for (int i = 0; i < strlen(str); i++) {
if (str[i] == ' ') {
count++;
}
}
printf('%d', count + 1);
return 0;
}
原文地址: https://www.cveoy.top/t/topic/piln 著作权归作者所有。请勿转载和采集!