统计字符串中空格和非空格的个数,例如,当字符串为:‘Goodbye 1234!***"则输出空格:1,非空格:15

如题所述

typedef size_t COUNT;
COUNT spaseCh = 0;
COUNT othersCh = 0;

const char* sc = inputStr;
while (*sc != '\0') {
 if (isspase(*sc)) {/* isspase是C标准库函数,功能是判别ASCII"空白"字符。需要包含ctype.h */
  ++spaseCh;
 }
 else {
  ++othersCh;
 }
 ++sc;
}
print spaseCh,othersCh
温馨提示:答案为网友推荐,仅供参考
相似回答