C++编程问题

2025-12-16 05:54:48
推荐回答(1个)
回答1:

#include
using
namespace
std;
void
main()
{
int
word,digital,other;
word=digital=other=0;
char
string[20],*p;
cout<<"Input:";
cin.getline(string,20);//改了下获取字符串的方式
//
*string=0;
p=string;
while(*p!='\0')
{
if(*p>'1'&&*p<'9')//这个地方
1到
9是字符
digital++;
else
if(*p>'a'&&*p<'z'||*p>'A'&&*p<'Z')
word++;
else
other++;
p++;
}
cout<<"word:
"<:"<:"<}
这样就没问题了,希望能够帮到你!