The isspace(), iscntrl(), ispunct(), isprint() and isgraph() C functions usage
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows 2003 Server Standard Edition
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)
Other info:
To do: Testing the C characters using the isspace(), iscntrl(), ispunct(), isprint() and isgraph() C functions
To show: The isspace(), iscntrl(), ispunct(), isprint() and isgraph() C functions usage
// using functions isspace(), iscntrl(), ispunct(), isprint(), isgraph()
#include <stdio.h>
#include <string.h>
int main(void)
{
printf("using functions isspace(), iscntrl(),\n");
printf("ispunct(), isprint(), isgraph()\n");
printf("-------------------------------------\n");
printf("According to isspace():\n");
isspace('\n') ? printf("Newline is a whitespace character\n") :
printf("Newline is not a whitespace character\n");
isspace('\t') ? printf("Horizontal tab is a whitespace character\n") :
printf("Horizontal tab is not a whitespace character\n");
isspace('%') ? printf("%% is a whitespace character\n") :
printf("%% is not a whitespace character\n");
printf("\nAccording to iscntrl():\n");
iscntrl('\n') ? printf("Newline is a control character\n") :
printf("Newline is not a control character\n");
iscntrl('$') ? printf("$ is a control character\n") :
printf("$ is not a control character\n");
printf("\nAccording to ispunct():\n");
ispunct('y') ? printf("y is a punctuation character\n") :
printf("y is not a punctuation character\n");
ispunct('\'') ? printf("\' is a punctuation character\n") :
printf("\' is not a punctuation character\n");
ispunct('"') ? printf("\" is a punctuation character\n") :
printf("\" is not a punctuation character\n");
printf("\nAccording to isprint():\n");
isprint('$') ? printf("$ is a printing character\n") :
printf("$ is not a printing character\n");
isprint('\a') ? printf("Alert is a printing character\n") :
printf("Alert is not a printing character\n");
printf("\nAccording to isgraph():\n");
isgraph('Q') ? printf("Q is a printing character other than a space\n") :
printf("Q is not a printing character other than a space\n");
isgraph(' ') ? printf("Space is a printing character other than a space\n"):
printf("Space is not a printing character other than a space\n");
return 0;
}
Output example:
using functions isspace(), iscntrl(),
ispunct(), isprint(), isgraph()
-------------------------------------
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():
y is not a punctuation character
' is 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
Press any key to continue . . .