C library functions -ispunct()
C Standard Library - <ctype.h>
Description
C Library Functionsint ispunct(int c)Checks whether the passed character is a punctuation character. A punctuation character can be any graphic character (as in isgraph) that is non-alphanumeric (as in isalnum).
Declaration
Below is the declaration of the ispunct() function.
int ispunct(int c);
Parameter
- cThis is the character to be checked.
Return Value
If c is a punctuation character, the function returns a non-zero value (true); otherwise, it returns 0 (false).
Example
The following example demonstrates the usage of the ispunct() function.
#include <stdio.h>
#include <ctype.h>
int main()
{
int var1 = 't';
int var2 = '1';
int var3 = '/';
int var4 = ' ';
if( ispunct(var1) )
{
printf("var1 = |%c| 是标点符号字符\n", var1 );
}
else
{
printf("var1 = |%c| 不是标点符号字符\n", var1 );
}
if( ispunct(var2) )
{
printf("var2 = |%c| 是标点符号字符\n", var2 );
}
else
{
printf("var2 = |%c| 不是标点符号字符\n", var2 );
}
if( ispunct(var3) )
{
printf("var3 = |%c| 是标点符号字符\n", var3 );
}
else
{
printf("var3 = |%c| 不是标点符号字符\n", var3 );
}
if( ispunct(var4) )
{
printf("var4 = |%c| 是标点符号字符\n", var4 );
}
else
{
printf("var4 = |%c| 不是标点符号字符\n", var4 );
}
return(0);
}
Let us compile and run the above program, which will produce the following result:
var1 = |t| 不是标点符号字符 var2 = |1| 不是标点符号字符 var3 = |/| 是标点符号字符 var4 = | | 不是标点符号字符other extensions