第1个回答 2012-04-02
#include<iostream>
using namespace std;
int main()
{
int i=0,A=0,a=0,space=0,number=0,other=0;
char *p,s[100];
cout<<"请输入一行文字:"<<endl;
cin.getline(s,100);
p=s;
while(*p!='\0')
{
if(('A'<=*p)&&(*p<='Z'))A++;
else
if(('a'<=*p)&&(*p<='z'))a++;
else
if(('0'<=*p)&&(*p<='9'))number++;
else
if(*p==' ')space++;
else
other++;
p++;
}
cout<<"大写字母:"<<A<<"小写字母:"<<a<<"数字:"<<number<<"空格:"<<space<<"其它符号:"<<other<<endl;
return 0;
}
第2个回答 2012-03-04
//以下修改完了:错的地方比较多!
#include<iostream>
using namespace std;
int main()
{
int i=0,A=0,a=0,space=0,d=0,other=0;//(1)你的i没有初始化
char *p,s[20];
memset(s,0,20);//(2)你的S没有初始化
while((s[i]=getchar())!='\n')i++;
p=s;
while(*p)//循环判断
{
if(('A'<=*p)&&(*p<='Z'))A++;
else
if(('a'<=*p)&&(*p<='z'))a++;//笔误z写成了a
else
if(('0'<=*p)&&(*p<='9'))d++;
else
if(*p==' ')space++;
else
other++;
p++;
}
cout<<"大写字母:"<<A<<"\n小写字母:"<<a<<"\n数字:"<<d<<"\n空格:"<<space<<"\n其它符号:"<<other<<endl;
return 0;
}
第3个回答 2012-03-04
你的getchar少个头文件
至于你的程序的输出结果是否正确我就没看了
加个#include "stdio.h"
就可以编译运行了