库里的函数:int ispunct ( int c )
使用:检查c是否是标点字符。标准“C”语言环境将标点符号视为非字母数字的所有图形字符(如isgraph中所示)(如isalnum中所示)。其他语言环境可能会将不同的字符选择视为标点字符,但无论如何它们都是isgraph而不是isalnum。如果确实c是标点符号 ,则值不为零(即,为真)。否则为零(即假)
例子
/* ispunct example */
#include <stdio.h>
#include <ctype.h>
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;
}
结果输出:这个句子有两个标点符号“,”与“!”
例子解释:str中只有“,”和“!”是标点符号,空格不是
库里的函数:int isspace ( int c )
使用:检查c是否为空格字符。对于“C”语言环境,空格字符是以下任意一种:
'' | (0×20) | 空间(SPC) |
'\ t' | (0×09) | 水平标签(TAB) |
'\ n' | (0X0A) | 换行(LF) |
'\ V' | (0x0B中) | 垂直标签(VT) |
'\F' | (0x0c) | 饲料(FF) |
'\ r' | 符(0x0D) | 回车(CR) |
其他语言环境可能会将不同的字符选择视为空格,但从不会为isalnum返回true 。
例子
/* isspace example */
#include <stdio.h>
#include <ctype.h>
int main ()
{
char c;
int i=0;
char str[]="Example sentence to test isspace\n function";
while (str[i])
{
c=str[i];
if (isspace(c)) c='\n';
putchar (c);
i++;
}
return 0;
}
结果输出:Example
sentence
to
test
isspace
function
例子解释:str中除了空格字符可以让isspace()返回为真,换行符也可以让isspace()返回为真