/*********************************************
* @brief 判断一个字符是否是标点符号
* @param ch 要判断的字符
* @return 是(非 0)否(0)是标点符号
********************************************/
int ispunct(int ch);
!subtitle:说明
判断字符 ch 是否是标点符号(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)。
标点符号还包括当前语言环境下的其它标点符号。
!subtitle:参数
ch - 要判断的字符
!subtitle:返回值
如果 ch 是标点符号,则返回非 0
如果不是,则返回 0
#include <stdio.h>
#include <ctype.h>
int main(void) {
int values[] = {'a', 'F', 'Z', '1', '2', ',', '*', ' ', '\t', '\n'};
for (int i = 0; i < sizeof(values) / sizeof(int); i += 1)
{
printf("ispunct('%c') 的结果为 %d\n", values[i], ispunct(values[i]));
}
return 0;
}
运行结果:
ispunct('a') 的结果为 0
ispunct('F') 的结果为 0
ispunct('Z') 的结果为 0
ispunct('1') 的结果为 0
ispunct('2') 的结果为 0
ispunct(',') 的结果为 4
ispunct('*') 的结果为 4
ispunct(' ') 的结果为 0
ispunct(' ') 的结果为 0
ispunct('
') 的结果为 0
C23 standard (ISO/IEC 9899:2024):
7.4.1.9 The ispunct function (p: TBD)
C17 standard (ISO/IEC 9899:2018):
7.4.1.9 The ispunct function (p: 145)
C11 standard (ISO/IEC 9899:2011):
7.4.1.9 The ispunct function (p: 200)
C99 standard (ISO/IEC 9899:1999):
7.4.1.9 The ispunct function (p: 181)
C89/C90 standard (ISO/IEC 9899:1990):
4.3.1.8 The ispunct function