ctype.h in CCtype.h/cctype> includes inbuilt functions to handle characters in C/C++ in the same way as the string.h header file contains inbuilt functions to handle Strings in C/C++. There are two sorts of characters- Printable Characters: The characters that are shown on the terminal are known as printable characters.
- Control Characters: Those who are ordered to carry out a particular action.
Character functions should only accept parameters of the integer type. Characters are typecast into integers with the matching ASCII values if they are supplied as arguments rather than an integer. For typical characters, the functions listed below are applied under the ctype.h/cctype> header file. For the characters of type, wide character functions are utilized wchar_t. S no. | Function | Description | Return value |
---|
1. | isalnum() | With this feature, alphanumeric characters are recognized. | If the supplied parameter is a non-alphanumeric character, it returns 0. if the supplied argument is an alphanumeric character, returns a value that is not zero. | 2. | isalpha() | The alphabets are distinguished from other characters by this function. | If the supplied parameter is not an alphabet, it returns 0. If the supplied input is an alphabet, it returns a non-zero result. | 3. | isblank() | This method distinguishes between blank spaces and other characters. | If the supplied input is not a blank space, it returns 0. returns a value other than zero if the supplied argument is a space. | 4. | iscntrl() | These control characters are recognised by this function: \n, \b, \t, and \r. | If the supplied argument is not a control character, it returns 0. if the passed argument is a control character, it returns a value other than zero. | 5. | isdigit() | This function recognises character-based numbers. | If the passed input is not an integer, it returns 0. if a number is the provided parameter, returns a value that is not zero. | 6. | islower() | Lowercase alphabet identification is done by this function. | If the supplied argument is not a lowercase alphabet, it returns 0. if the supplied parameter is a lowercase alphabet, it returns a value other than zero. | 7. | isprint() | The printable characters are identified by this function. | If the supplied argument is an unprintable character, it returns 0. if the supplied argument is a printable character, it returns a value other than zero. | 8. | ispunct() | Punctuation characters are identified by this function (characters that are neither alphanumeric nor space). | If the supplied argument is not a punctuation character, it returns 0. If the passed argument is a punctuation character, it returns a value other than zero. | 9. | isspace() | White-space characters are identified using this function. | If the supplied argument is not a white-space character, it returns 0. If the passed parameter is a white-space character, it returns a value other than zero. | 10. | isupper() | The uppercase alphabets are recognised by this function. | If the supplied parameter is not an uppercase alphabet, it returns 0. If the supplied parameter is an uppercase alphabet, a nonzero result is returned. | 11. | isxdigit() | The hexadecimal digit is identified using this function. | If the supplied parameter is not a hexadecimal digit, it returns 0. If the supplied parameter is a hexadecimal digit, it returns a value other than zero. | 12. | tolower() | This function changes the alphabet from uppercase to lowercase. | returns the relevant uppercase alphabet's lowercase equivalent. | 13. | toupper() | This function changes the alphabet from lowercase to uppercase. | Returns the appropriate lowercase alphabet's uppercase counterpart. |
Here are some examples of how to use some of the aforementioned functions: Example 1: The software below counts the alphabets and digits: Output The number of alphabets are 23
The number of digits are 6
………………………………………………..
Process executed in 1.11 seconds
Press any key to continue.
Explanation In the above example of program in C, we have demonstrated the use of isalpha() and isdigit() function which will count the number of alphabets and digits. Example 2: The software that follows counts the alphabets' upper- and lowercase letters and changes their case: Output No. of uppercase alphabets are 3
No. of lowercase alphabets are 21
hEELLO, wELCOME TO JAVAtPOINT
...........................................................
Process executed in 1.11 seconds
Press any key to continue
Explanation In the above example of program in C, we have demonstrated the use of isupper() and islower() which will count the alphabets' upper and lowercase letters and changes their case. Example 3: The following software creates a new line for each word it prints: Output Hi
Everyone.
Welcome
to
javaTpoint.com
............................
Process executed in 1.11 seconds
Press any key to continue.
Explanation In the above example of program in C, we have demonstrated the use of isblank() function which a new line for each word it prints.
|