http://www.cplusplus.com/reference/cctype/
isalnum
View Code
/* isalnum example */
/*Checks whether c is either a decimal digit or an uppercase or lowercase letter.*/
#include <stdio.h>
#include <cctype>
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;
}
isalpha
View Code
/* isalpha example */
#include <stdio.h>
#include <cctype>
int main ()
{
int i=0;
char str[]="C++";
while (str[i])
{
if (isalpha(str[i])) printf ("character %c is alphabeticn",str[i]);
else printf ("character %c is not alphabeticn",str[i]);
i++;
}
return 0;
}
isdigit
View Code
/* isdigit example */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main ()
{
char str[]="1776ad";
int year, i=0;
while(isdigit(str[i])) i++;
printf("%dn",i-1);
if (isdigit(str[0]))
{
year = atoi (str);
printf ("The year that followed %d was %d.n",year,year+1);
}
return 0;
}
islower and toupper
View Code
/* islower example */
#include <stdio.h>
#include <ctype.h>
int main ()
{
int i=0;
char str[]="Test String.n";
char c;
while (str[i])
{
c=str[i];
if (islower(c)) c=toupper(c);
putchar (c);
i++;
}
return 0;
}
ispunct
View Code
/* ispunct example */
/*Checks whether c is a punctuation character*/
#include <stdio.h>
#include <cctype>
int main ()
{
int i=0;
int cx=0;
char str[]="Hello, welcome!";
while (str[i])
{
if (ispunct(str[i])) cx++;
i++;
}
printf ("Sentence contains %d punctuation characters.n", cx);
return 0;
}
isupper and tolower
View Code
/* isupper example */
#include <stdio.h>
#include <cctype>
int main ()
{
int i=0;
char str[]="Test String.n";
char c;
while (str[i])
{
c=str[i];
if (isupper(c)) c=tolower(c);
putchar (c);
i++;
}
return 0;
}
原文链接: https://www.cnblogs.com/zhang1107/archive/2013/03/20/2971077.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/81422
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!