注册 登录
编程论坛 C++教室

[求助]不懂错在那里

chenkuanyi 发布于 2007-04-21 16:28, 377 次点击

#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;
void main()
{
int n=0;
char S1[50];
cout<<"输入字符串:"<<endl;
cin.getline(S1,50);
int i=0;
while(S1[i]!='\0')
{
if(isdigit(S1[i]))
++n;
}
cout<<"_______"<<endl;
cout<<n<<endl;

}

编译没有问题,在输入后,但是显示不了结果!
为什么??????
谢谢解答啊!

[此贴子已经被作者于2007-4-21 17:16:01编辑过]

2 回复
#2
yushui2007-04-21 18:38

#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;
void main()
{
int n=0;
char S1[50];
cout<<"输入字符串:"<<endl;
cin.getline(S1,50);
int i=0;
while(S1[i]=='\0')
{
if(isdigit(S1[i]))
++n;
++i;
}
cout<<"_______"<<endl;
cout<<n<<endl;

}

我不知道if(isdigit(S1[i]))这句怎么在我这儿不能实现,其他的小错误帮你改了

#3
chenkuanyi2007-04-21 18:59

谢了啊!

能运行了!

1