# 指针练习--字符串统计

int main()
{
char str[80];
int numA,numa,numt;
cin.getline(str,80);
count(str,&numA,&numa,&numt);
cout<<"大写字母个数为 "<<numA<<endl
<<"小写字母个数为 "<<numa<<endl
<<"其他字符个数为 "<<numt<<endl;
return 0;
}

``WVGA:800*480,HDTV:1080i,33.75kHz``

``````大写字母个数为 9

``````#include<stdio.h>
int main()
{
char str[80];
int numA=0,numa=0,numt=0;
int i=0;
gets(str);
while(str[i]!='\0')
{
if(str[i]>='A'&&str[i]<='Z')
numA++;
else if(str[i]>='a'&&str[i]<='z')
numa++;
else
numt++;
i++;

}
printf("大写字母个数为 %d\n小写字母个数为 %d\n其他字符个数为 %d",numA,numa,numt);
/*cin.getline(str,80);
count(str,&numA,&numa,&numt);
cout<<"大写字母个数为 "<<numA<<endl
<<"小写字母个数为 "<<numa<<endl
<<"其他字符个数为 "<<numt<<endl;*/
return 0;
}
``````

``````#include <iostream>
using namespace std;
void count(char *str, int *pnumA,int *pnuma,int *pnumt)
{
int i=0;
*pnumA=*pnuma=*pnumt=0;
while(str[i]!='\0')
{
if(str[i]>='A'&&str[i]<='Z')   (*pnumA)++;
else if (str[i]>='a'&&str[i]<='z') (*pnuma)++;
else  (*pnumt)++;
i++;
}
}
int main()
{
char str[80];
int numA,numa,numt;
cin.getline(str,80);
count(str,&numA,&numa,&numt);
cout<<"大写字母个数为 "<<numA<<endl
<<"小写字母个数为 "<<numa<<endl
<<"其他字符个数为 "<<numt<<endl;
return 0;
}``````