Using functions isspace, iscntrl, ispunct, isprint, isgraph : char function « Data Type « C Tutorial






#include <stdio.h>
#include <ctype.h>

int main()
{
   printf( "%s\n%s%s%s\n%s%s%s\n%s%s\n\n", 
       "According to isspace:", 
       "Newline", isspace( '\n' ) ? " is a " : " is not a ",
       "whitespace character", "Horizontal tab",
       isspace( '\t' ) ? " is a " : " is not a ", 
       "whitespace character",
       isspace( '%' ) ? "% is a " : "% is not a ",
       "whitespace character" );

   printf( "%s\n%s%s%s\n%s%s\n\n", "According to iscntrl:", 
       "Newline", iscntrl( '\n' ) ? " is a " : " is not a ",
       "control character", iscntrl( '$' ) ? "$ is a " : 
       "$ is not a ", "control character" );

   printf( "%s\n%s%s\n%s%s\n%s%s\n\n", 
       "According to ispunct:",
       ispunct( ';' ) ? "; is a " : "; is not a ", 
       "punctuation character",
       ispunct( 'Y' ) ? "Y is a " : "Y is not a ",
       "punctuation character",
       ispunct( '#' ) ? "# is a " : "# is not a ",
       "punctuation character" );

   printf( "%s\n%s%s\n%s%s%s\n\n", "According to isprint:",
       isprint( '$' ) ? "$ is a " : "$ is not a ", 
       "printing character", 
       "Alert", isprint( '\a' ) ? " is a " : " is not a ",
       "printing character" );

   printf( "%s\n%s%s\n%s%s%s\n",  "According to isgraph:",
       isgraph( 'Q' ) ? "Q is a " : "Q is not a ",
       "printing character other than a space",
       "Space", isgraph( ' ' ) ? " is a " : " is not a ",
       "printing character other than a space" );

   return 0; 

}
According to isspace:
Newline is a whitespace character
Horizontal tab is a whitespace character
% is not a whitespace character

According to iscntrl:
Newline is a control character
$ is not a control character

According to ispunct:
; is a punctuation character
Y is not a punctuation character
# is a punctuation character

According to isprint:
$ is a printing character
Alert is not a printing character

According to isgraph:
Q is a printing character other than a space
Space is not a printing character other than a space








2.15.char function
2.15.1.Using functions islower, isupper, tolower, toupper
2.15.2.Using functions isdigit, isalpha, isalnum, and isxdigit
2.15.3.Using functions isspace, iscntrl, ispunct, isprint, isgraph