写一个函数,输入一串字符串,求这个字符串中有多少个英文,多少空格,多少个数字,多少个其它字符

代码
#include "stdafx.h"
#include <iostream>

using namespace std;

void fun1(char* str,int *a, int *b, int *c, int *d)
{
	if(str == NULL) return;
	int iNumofAlp = 0;
	int iNumofNumber = 0;
	int iNumofBlank = 0;
	int iNumofOther = 0;
	
	while(*str != '\0')
	{
		if((('a' <= *str)&&('z' >= *str)) || (('A' <= *str) && ('Z' >= *str)))
			iNumofAlp++;
		else if('0'<*str&&*str<'9')
			iNumofNumber++;
		else if(*str==' ')
			iNumofBlank++;
		else
			iNumofOther++;
		str++;
	}
	*a = iNumofAlp;	
	*b = iNumofNumber;
	*c = iNumofBlank;
	*d = iNumofOther;
}

int _tmain(int argc, _TCHAR* argv[])
{
	char *str = "d ggfdg  dgdfsgrege32435356445 ,. frg . ";
	int iNumofAlp = 0;
	int iNumofNumber = 0;
	int iNumofBlank = 0;
	int iNumofOther = 0;

	fun1(str, &iNumofAlp, &iNumofNumber, &iNumofBlank, &iNumofOther);

	cout<<"英文字母的个数是:"<<iNumofAlp<<endl;
	cout<<"数字的个数是:"<<iNumofNumber<<endl;
	cout<<"空格的个数是:"<<iNumofBlank<<endl;
	cout<<"其他字符的个数是:"<<iNumofOther<<endl;

	return 0;
}

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页