输入一行字符,统计其中的英文字符、数字字符、空格和其他字符的个数。
输入提示信息:"Please input a string:"
输入字符串用gets() 输出提示信息和格式:
"English character: %d\n"
"digit character: %d\n"
"space: %d\n"
"other character: %d\n"
#include <stdio.h>#include <string.h>#define ARR_SIZE 80int main(){ char str[ARR_SIZE]; //1int len, i, letter = 0, digit = 0, space = 0, others = 0; //1printf("Please input a string:"); //1gets(str); //1for (i = 0; str[i] != '\0'; i++) //1{ if (str[i] >= 'a' && str[i] <= 'z' || str[i] >= 'A' && str[i] <= 'Z') //1letter ++;//统计英文字符else if (str[i] >= '0' && str[i] <= '9' ) //1digit ++;//统计数字字符else if (str[i] == ' ' ) //1space ++;//统计空格elseothers ++;//统计其他字符的个数} printf("English character: %d\n", letter); //1printf("digit character: %d\n", digit); //1printf("space: %d\n", space); //1printf("other character: %d\n", others); //1return 0;