C 循环统计输入的单词个数和字符长度

C 循环统计输入的单词个数和字符长度

#include <stdio.h>
#include <Windows.h>

int main(void) {
    char word[128];
    int count = 0;
    int length = 0;
    
    printf("请输入任意多个单词:\n");
    
    while (1) {
        if (scanf("%s",word) != -1) {
            count++;
            length += strlen(word);
        } else {
            break;
        }
    }
    
    printf("你输入的单词个数为:%d\n", count);
    printf("你输入的字符长度为:%d\n", length);

    system("pause");
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/tanghaiyong/p/11331282.html
今日推荐