isdigit(int ch) 具体用法

来源:百度知道 编辑:UC知道 时间:2024/06/06 11:01:07
比如,我让他输两个数字
它输入一个字符,我要告诉他,//it is wrong try to give two integers://让他再输,

#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main(void)
{
char Str[10] = "";
while(1)
{
scanf("%9s", Str);
if ( strlen(Str) == 2 )
{
int i;
for(i = 0; i < 2; ++i)
if ( ! isdigit(Str[i]) )
break;
if ( i < 2 )
printf("it is wrong try to give two integers:");
else
break;
}
else
printf("it is wrong try to give two integers:");
}
return 0;
}

// int isdigit(int ch); 如果字符ch是数字, 则返回非0;否则返回0.

// ex. : 判断 '9' 是否为数字, isdigit('9')
// ex. : 判断 ASCII码为 52的字符是否为数字, isdigit(52)

JAVA版:根据你的需求自已改写下方法就可以了.
public String isDigit(int ch){
boolean flag = fa