库:ctype.h
库里的函数:int isalnm(int c)
使用:检查字符是否为字母数字,是的话返回不为0,不是的话返回0
例子:
/* isalnum example */
#include <stdio.h>
#include <ctype.h>
int main ()
{
int i;
char str[]="c3po...";
i=0;
while (isalnum(str[i])) i++;
printf ("The first %d characters are alphanumeric.\n",i);
return 0;
}
结果输出:The first 4 characters are alphanumeric.
库里的函数:int isalpha(int c)
使用:检查字符是否是字母,是的话返回不为0,不是的话返回0
例子:
* isalpha example */
#include <stdio.h>
#include <ctype.h>
int main ()
{
int i=0;
char str[]="C++";
while (str[i])
{
if (isalpha(str[i]))
printf ("character %c is alphabetic\n",str[i]);
else
printf ("character %c is not alphabetic\n",str[i]);
i++;
}
return 0;
}
结果输出:character C is alphabetic
character + is not alphabetic
character + is not alphabetic