庫: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