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;
}

 

posted @ 2019-08-10 13:16  你爱过大海我爱过你  阅读(369)  评论(0编辑  收藏  举报