从键盘输入一个字符串 使用指针判断字符串中大写字母 小写字母 数字 的个数并输出

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<iostream>
#include<string.h>
using namespace std;
void fun(char *p)
{ int i;
int a,b,c;
a=b=c=0;
for(i=0;i<=strlen(p);i++)
{ if(*(p+i)>='A'&&*(p+i)<='Z')
a++;
if(*(p+i)>='a'&&*(p+i)<='z')
b++;
if(*(p+i)>='0'&&*(p+i)<='9')
c++;
// p++;
}
cout<<"该字符串中大写字母有"<<a<<"个"<<"小写字母有"<<b<<"个"<<"数字有"<<c<<"个"<<endl;




}
void main()
{ void fun(char *p);
char a[1000];
cout<<"请输入字符串"<<endl;
fun(gets(a));
}