Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C library function - ispunct()

C library function - ispunct()

C Standard Library - <ctype.h> C Standard Library -

Description

C Library Function int ispunct(int c) Checks whether the passed character is a punctuation character. A punctuation character can be any graphical character (as in isgraph) that is not alphanumeric (as in isalnum).

Declaration

Here is the declaration of the ispunct() function.



int ispunct(int c);

Parameters

Return Value

If c is a punctuation character, the function returns a nonzero value (true); otherwise it returns 0 (false).

Example

The following example demonstrates the use of the ispunct() function.



#include 

#include 



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's compile and run the above program, which will produce the following result:



var1 = |t| 不是标点符号字符

var2 = |1| 不是标点符号字符

var3 = |/| 是标点符号字符

var4 = | | 不是标点符号字符

C Standard Library - <ctype.h> C Standard Library -