![]() |
#2
邓士林2013-05-08 20:55
|
#include<iostream>
using namespace std;
int main()
{
int letter=0,digit=0,space=0,other=0,i;
char *p,s[37];
cout<<"input a string:";
while((s[i]=getchar())!='\n') i++;
p=&s[0];
while(*p!='\n')
{
if(('A'<=*p)&&(*p<='Z'))
++letter;
else if(('a'<=*p)&&(*p<='z'))
++letter;
else if((*p>='0')&&(*p<='9'))
++digit;
else if(*p==' ')
++space;
else ++other;
p++;
}
cout<<"letter:"<<letter<<'\t'<<"digit:"<<digit<<'\t'<<"space:"<<space<<'\t'<<"other:"<<other<<endl;
return 0;
}
此代码,编译时通过,但是在运行时,数完字符串,他就突然中断了。请教大神帮助!