求助C++题目

来源:百度知道 编辑:UC知道 时间:2024/05/23 14:18:47
写一个函数,由实参传来一个字符串,统计此字符串中字母、数字、空格和其它字符的个数,在主函数中输入字符串以及输出上述的结果。

void CountStr( char* src, int n, int* word, int* dig, int* space, int* others )
{
int i = 0;
while( i < n )
{
if( *src <= 'z' && *src >= 'a' )
{
(*word)++;
}
else if( *src <= 'Z' && *src >= 'A' )
{
(*word)++;
}
else if( *src == ' ' )
{
(*space)++;
}
else if( *src <= '9' && *src >= '0' )
{
(*dig)++;
}
else
{
(*others)++;
}

src++;
i++;
}
}

楼上的,你的程序接收的字符串中根本就没有空格,干吗还要在CountStr函数中计算空格的个数???

参考:
#include<iostream>
using namespace std;
void count(char ch,int &letter,int &number,int &space,int &others)
{
if((ch>='A'&&ch<='Z')||(ch>='a'&&ch<='z'))
letter++;
else if(ch>='0&