C经典 输入字符串,并统计字母个数,首字母大写

分析:是不是字母根据空格判断,首字母大写,只要把字母-32web

#include <stdio.h>

int main(int argc, const char * argv[])
{

    // 定义数组
    char ch[50];
    int words = 0;//用来判断是不是字母
    int count = 0;//统计字母的个数
    // 提示用户输入
    printf("请输入字符串\n");
    // 用户输入
    gets(ch);
    // 循环数组
    for (int i = 0; ch[i] != '\0'; i ++) {
        if (ch[i]==' ') {// 判断是否为空
            words = 0;
        }else if(words == 0) {
            count ++; // 若是为空,就 +1
            ch[i] = ch[i] - 32 ;//把首字母变大写
            words = 1;
        }

    }
     // 打印输出
    printf("字母总共有:%d,字符串:%s",count,ch);


    printf("\n");
    return 0;
}