曲径通幽论坛

标题: ispunct() -- 测试是否为标点符号或特殊符号 [打印本页]

作者: beyes    时间: 2011-12-17 12:42
标题: ispunct() -- 测试是否为标点符号或特殊符号
ispunct() 函数的原型如下:
[C++] 纯文本查看 复制代码
#include <ctype.h>
int ispunct(int c);[/quote]
该函数可用来检查其参数 c 是否为标点符号或特殊符号,是则返回 TRUE,否则返回 NULL 。该函数也是一个宏函数。

测试代码
[mw_shl_code=cpp,true]#include <stdio.h>
#include <ctype.h>

int main()
{
        char str[] = "a!b@c#d$A%B^C&D*E(F)1_2+3-4=5\6|7[8]9{}0<K>L,M.N/v?z~x`";
        int i;

        for (i = 0; str != 0; i++)
                if (ispunct(str))
                        printf ("%d---%c\n", i, str);

        return 0;
}

运行输出:
1---!
3---@
5---#
7---$
9---%
11---^
13---&
15---*
17---(
19---)
21---_
23---+
25----
27---=
30---|
32---[
34---]
36---{
37---}
39---<
41--->
43---,
45---.
47---/
49---?
51---~
53---`





欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2