我有一个简单的问题;如何防止用户输入字母或数字?
下面是代码:
#include<stdio.h>
main(){
int input;
printf("Choose a numeric value");
scanf("%d",&input);
}
我希望用户只输入数字... 所以它必须是这样的:
#include<stdio.h>
main(){
int input;
printf("Choose a numeric value");
do{
scanf("%d",&input);
}while(input!= 'something');
}
我的问题是,我不知道什么东西要替换...我怎样才能防止用户输入字母字符?
编辑
我刚刚得到一些有趣的事情:
#include<stdio.h>
main(){
int input;
printf("Choose a numeric value");
do{
scanf("%d",&input);
}while(input!= 'int');
}
添加“诠释”将继续只要我输入数字的循环,我想“炭”,但没有工作..肯定有什么字母是正确的? :S 请回复!
感谢您的帮助!
删除标签的极限选择到'和'数字',我认为在'限制选择'方面没有任何一种开发专家。 – 2010-05-09 00:06:21
可能重复[如何防止用户输入不正确的输入?](http://stackoverflow.com/questions/2795252/how-to-prevent-users-from-typing-incorrect-inputs) – 2010-05-09 04:32:08