Given a character we need to find if it printable or not. We also need to find if it is control character or not. A character is known as printable character if it occupies printing space.
For the standard ASCII character set (used by the “C” locale), control characters are those between ASCII codes 0x00 (NUL) and 0x1f (US), plus 0x7f (DEL).
Input : a Output :a is printable character a is not control character Input :\r Output : is not printable character is control character
To find the difference between a printable character and a control character we can use some predefined functions, which are declared in the “ctype.h” header file.
The isprint() function checks whether a character is a printable character or not. isprint() function takes single argument in the form of an integer and returns a value of type int. We can pass a char type argument internally they acts as a int by specifying ASCII value.
The iscntrl() function is used to checks whether a character is a control character or not. iscntrl() function also take a single argument and return an integer.
a is printable character a is not control character
This article is contributed by Bishal Kumar Dubey. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- rand() and srand() in C/C++
- strftime() function in C/C++
- Pointers in C and C++ | Set 1 (Introduction, Arithmetic and Array)
- Clearing The Input Buffer In C/C++
- scanf() and fscanf() in C - Simple Yet Poweful
- getchar_unlocked() - faster input in C/C++ for Competitive Programming
- Problem with scanf() when there is fgets()/gets()/scanf() after it
- C Program to print numbers from 1 to N without using semicolon?
- sprintf() in C
- Operators in C | Set 1 (Arithmetic Operators)
- Functions in C/C++
- Bitwise Operators in C/C++
- Commonly Asked C Programming Interview Questions | Set 2
- Scansets in C
- Understanding "register" keyword in C