库里的函数:int isdigit ( int c );
使用:检查c是否为十进制数字字符。十进制数字是以下任意一个:0 1 2 3 4 5 6 7 8 9。如果确实c是十进制数字字符 ,则值不为零(即,为真),否则为零(即假)。
例子
/* isdigit example */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main ()
{
char str[]="1776ad";
int sum=0,i;
for(i=0;i<6;i++)
{
if(isdigit(str[i]))
{
sum=sum+1;
}
}
printf ("The number of digital character of str 1776ad is %d.\n",sum);
return 0;
}
结果输出:The number of digital character of str 1776ad is 4
库里的函数:int isgraph ( int c );
使用:检查c是否是具有图形表示的字符。除了空格字符('')之外。具有图形表示的字符都是可以打印的字符(由isprint确定)。如果确实c具有图形(即可打印)表示作为字符 ,则值不为零(即,为真),否则为零(即假)。
例子
/* isgraph example */
#include <stdio.h>
#include <ctype.h>
#include <ctype.h>
main(){
char str[] = "a5 @;";
int i;
for(i = 0; str[i] != 0; i++)
{
if(isgraph(str[i]))
printf("str[%d] is printable character:%d\n", i, str[i]);
}
}
结果输出:str[0] is printable character:97
str[1] is printable character:53
str[3] is printable character:64
str[4] is printable character:59
例子解释:非打印字符 或 空格字符 时,isgraph判断为0,str[2]为空格字符,结果输出无str[2]