c语言——输入一行文字,找出其中大写字母,小写字母,空格,数字以及其他字符各有多少?

谢谢了~用指针编写
我们要求用指针编写

#include <iostream>
#include <string.h>
#include <ctype.h>
using namespace std;

int main()
{
char s[80];
gets(s);

int upper,lower,number,space,other;
upper=lower=number=space=other=0;
char *p;
for(p=s;*p;p++)
{
if(isupper(*p)) upper++;
else if(islower(*p)) lower++;
else if(isdigit(*p)) number++;
else if(isspace(*p)) space++;
else other++;
}

cout<<"大写字母有"<<upper<<"个"<<endl;
cout<<"小写字母有"<<lower<<"个"<<endl;
cout<<"数字有"<<number<<"个"<<endl;
cout<<"空格有"<<space<<"个"<<endl;
cout<<"其他有"<<other<<"个"<<endl;

return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-05-27
看错了,要求是用指针编写,不写了,给个非指针的

#include<stdio.h>
#include <stdlib.h>
int main()
{
int ch,en=0,n=0,s=0,q=0,o=0;
system("cls");
printf("Please Input:\n");
while((ch=getchar())!='\n')
{
if(ch<='z'&&ch>='a') en++;
else if(ch<='Z'&&ch>='A')
q++;
else if(ch==' ') s++;
else if(ch<='9'&&ch>='0') n++;
else o++;
}
printf(" Big letters Number: %d\n Small letters Number:%d\nNum Number: %d\n Spaces Number: %d\n Other Number: %d\n",q,en,n,s,o);
getch();
}
第2个回答  2008-05-27
# include<stdio.h>

void main()
{
char c; int letters=0,space=0,digit=0,other=0;
printf("enter:");
while((c=getchar())!='\n')
{ if( c>='a'&&c<='z'||c>='A'&&c<='Z')
letters++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else other++;
}
printf("letters=%d,space=%d,digit=%d,other=%d\n",letters,space,digit,other);
getch();
}
书上的练习题吧 呵呵 前段时间做过
相似回答