{"id":104374,"date":"2020-02-27T10:21:00","date_gmt":"2020-02-27T10:21:00","guid":{"rendered":"https:\/\/www.softwaretestinghelp.com\/?page_id=104374"},"modified":"2025-04-01T08:13:38","modified_gmt":"2025-04-01T08:13:38","slug":"cpp-character-functions","status":"publish","type":"page","link":"https:\/\/www.softwaretestinghelp.com\/cpp-character-functions\/","title":{"rendered":"C++ Character Classification And Tranformation Functions"},"content":{"rendered":"<p><strong>This Tutorial Explains C++ Character &amp; Transformation Functions with Examples. Some Important Functions Covered are isdigit, islower, isupper, isalpha etc.:<\/strong><\/p>\n<p>In our previous tutorial on \u201clibrary functions\u201d, we saw the various headers that provide numerous functions that operate on different data types. The header <strong>&lt;cctype.h&gt;<\/strong> is one such header that contains a set of functions that classify and manipulate individual characters.<\/p>\n<p><strong>=&gt; <a href=\"https:\/\/www.softwaretestinghelp.com\/cpp-tutorials\/\">Visit Here To Learn C++ From Scratch.<\/a><\/strong><\/p>\n<p><em><strong> <\/strong><\/em><\/p>\n<p>The functions declared in &lt;cctype.h&gt; header, take a single character (int equivalent) as a parameter and return an integer value that can either be a Boolean value or a character value. A value 0 (zero) indicates false while a value other than 0 (non-zero) indicates true.<\/p>\n<p><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/C-Character-functions.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-104880\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/C-Character-functions.png\" alt=\"C++ Character functions\" width=\"650\" height=\"366\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/C-Character-functions.png 650w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/C-Character-functions-300x169.png 300w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/a><\/p>\n<p>These single character functions can be used in the program by including the header &lt;cctype.h&gt;. These functions are widely used and accepted and are extremely useful in C++ programming for testing and transforming or manipulating characters.<\/p>\n<p>In this tutorial, we will discuss the various character functions and see how each of these functions can be used in a program.<\/p>\n<h2>C++ Character Functions<\/h2>\n<p><strong>C++ character functions are the functions that take only a single character as a parameter (casted to int) and return a result. These can be classification functions like isalpha, isalnum, isdigit, islower, isupper, etc. to name a few and transforming functions like toupper and tolower that transform a given character into uppercase or lowercase respectively.<\/strong><\/p>\n<p>In the header &lt;cctype.h&gt;, we have two types of functions defined as stated below.<\/p>\n<p><span style=\"color: #ff6600;\"><strong>(i) Character Classification Functions<\/strong><\/span><\/p>\n<p>Character classification functions are used to check if the single character passed as an argument to the function belongs to a certain category.<\/p>\n<p><strong>We have tabularized the character classification functions included in &lt;cctype.h&gt; header below:<\/strong><\/p>\n\n<div id=\"tablepress-983-scroll-wrapper\" class=\"tablepress-scroll-wrapper\">\n<table id=\"tablepress-983\" class=\"tablepress tablepress-id-983 tablepress-responsive\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">No<\/th><th class=\"column-2\">Function name<\/th><th class=\"column-3\">Function Purpose<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\">1<\/td><td class=\"column-2\">isalnum<\/td><td class=\"column-3\">Checks if a given character is alphanumeric<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">2<\/td><td class=\"column-2\">isalpha<\/td><td class=\"column-3\">Checks if the character is alphabetic<\/td>\n<\/tr>\n<tr class=\"row-4\">\n\t<td class=\"column-1\">3<\/td><td class=\"column-2\">isblank<\/td><td class=\"column-3\">Checks if the character is blank<\/td>\n<\/tr>\n<tr class=\"row-5\">\n\t<td class=\"column-1\">4<\/td><td class=\"column-2\">iscntrl<\/td><td class=\"column-3\">Checks if the given character is a control character<\/td>\n<\/tr>\n<tr class=\"row-6\">\n\t<td class=\"column-1\">5<\/td><td class=\"column-2\">isdigit<\/td><td class=\"column-3\">Checks if the given character is a decimal digit<\/td>\n<\/tr>\n<tr class=\"row-7\">\n\t<td class=\"column-1\">6<\/td><td class=\"column-2\">isgraph<\/td><td class=\"column-3\">Checks if the given character has a graphical representation<\/td>\n<\/tr>\n<tr class=\"row-8\">\n\t<td class=\"column-1\">7<\/td><td class=\"column-2\">islower<\/td><td class=\"column-3\">Checks if a given character is lowercase<\/td>\n<\/tr>\n<tr class=\"row-9\">\n\t<td class=\"column-1\">8<\/td><td class=\"column-2\">isprint<\/td><td class=\"column-3\">Checks if the character is a printable character<\/td>\n<\/tr>\n<tr class=\"row-10\">\n\t<td class=\"column-1\">9<\/td><td class=\"column-2\">ispunct<\/td><td class=\"column-3\">Checks if the character is a punctuation character<\/td>\n<\/tr>\n<tr class=\"row-11\">\n\t<td class=\"column-1\">10<\/td><td class=\"column-2\">isspace<\/td><td class=\"column-3\">Checks if the character is a white-space<\/td>\n<\/tr>\n<tr class=\"row-12\">\n\t<td class=\"column-1\">11<\/td><td class=\"column-2\">isupper<\/td><td class=\"column-3\">Checks if the given character is uppercase<\/td>\n<\/tr>\n<tr class=\"row-13\">\n\t<td class=\"column-1\">12<\/td><td class=\"column-2\">isxdigit<\/td><td class=\"column-3\">Checks if the character hexadecimal digit<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<!-- #tablepress-983 from cache -->\n<p><span style=\"color: #ff6600;\"><strong>(ii) Character Transforming Functions<\/strong><\/span><\/p>\n<p><strong>Character transforming functions convert between cases. The following functions are included in &lt;cctype.h&gt; file.<\/strong><\/p>\n\n<div id=\"tablepress-984-scroll-wrapper\" class=\"tablepress-scroll-wrapper\">\n<table id=\"tablepress-984\" class=\"tablepress tablepress-id-984 tablepress-responsive\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">No<\/th><th class=\"column-2\">Function Name<\/th><th class=\"column-3\">Function purpose<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\">1<\/td><td class=\"column-2\">tolower<\/td><td class=\"column-3\">Converts uppercase character to lowercase <\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">2<\/td><td class=\"column-2\">toupper<\/td><td class=\"column-3\">Converts lowercase character to uppercase <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<!-- #tablepress-984 from cache -->\n<p>Let&#8217;s see each of the character functions (classification and transforming) in detail. We will also present a simple C++ programming example for each of the functions.<\/p>\n<h3><span style=\"color: #ff6600;\">Isalnum<\/span><\/h3>\n<p><strong> Function Prototype: <\/strong>int isalnum(int c);<\/p>\n<p><strong> Parameter(s): <\/strong>c=&gt; A character which should be checked if alphanumeric or not<\/p>\n<p><strong> Return Value: <\/strong><\/p>\n<p>non-zero =&gt; c is alphanumeric<\/p>\n<p>0 =&gt; c is not alphanumeric<\/p>\n<p><strong> Description: <\/strong>This function checks if a given character c is alphanumeric or not. By alphanumeric, it means a character is between A(a)-Z(z) or 0 to 9.<\/p>\n<p>In C++, this function is locale-specific and its definition is present in header &lt;locale&gt;.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong> Example:<\/strong><\/span><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">#include &lt;iostream&gt;\r\n#include &lt;cctype&gt;\r\nusing namespace std;\r\nint main()\r\n{\r\n   char chary&#x5B;12] = &quot;Hello World&quot;; \r\n  \r\n    \/\/ checking for isalnum() function \r\n    for (int i=0; i&lt;12; i++) \r\n    { \r\n        if (isalnum(chary &#x5B;i])) \r\n            cout &lt;&lt; chary &#x5B;i] &lt;&lt; &quot; is alphanumeric&quot; &lt;&lt; endl; \r\n        else\r\n            cout &lt;&lt; chary &#x5B;i]  &lt;&lt; &quot; is not alphanumeric&quot; &lt;&lt; endl; \r\n    } \r\n   cout &lt;&lt; endl; \r\n} <\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/1.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-104426\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/1.png\" alt=\"Isalnum output\" width=\"234\" height=\"365\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/1.png 234w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/1-192x300.png 192w\" sizes=\"(max-width: 234px) 100vw, 234px\" \/><\/a><\/p>\n<h3><span style=\"color: #ff6600;\">Isalpha<\/span><\/h3>\n<p><strong> Function Prototype: <\/strong>int isalpha(int c);<\/p>\n<p><strong> Parameter(s): <\/strong>c-&gt; Character that is to be checked if alphabetic or not.<\/p>\n<p><strong> Return Value:<\/strong><\/p>\n<p>non-zero =&gt; c is alphabetic<\/p>\n<p>0 =&gt; not alphabetic<\/p>\n<p><strong> Description: <\/strong>This function checks if a given character c is alphabetic character i.e. among lowercase and uppercase letters. Like isalnum this function also depends on the locale that we are using.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong> Example:<\/strong><\/span><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">#include &lt;iostream&gt;\r\n#include &lt;cctype&gt;\r\nusing namespace std;\r\nint main()\r\n{\r\n    char ch_alpha&#x5B;5] = &quot;sth1&quot;; \r\n    for (int i=0; i&lt;5; i++) { \r\n        if (isalpha(ch_alpha&#x5B;i])) \r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is an alphabet&quot; &lt;&lt; endl; \r\n        else\r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is not an alphabet&quot; &lt;&lt; endl; \r\n    } \r\n    cout &lt;&lt; endl; \r\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/2.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-104427\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/2.png\" alt=\"Isalpha output\" width=\"196\" height=\"140\" \/><\/a><\/p>\n<h3><span style=\"color: #ff6600;\">Isblank<\/span><\/h3>\n<p><strong> Function Prototype: <\/strong>int isblank(int c);<\/p>\n<p><strong> Parameter(s): <\/strong>c=&gt; Character which is to be checked.<\/p>\n<p><strong> Return Value:<\/strong><\/p>\n<p>non-zero =&gt; character is blank<\/p>\n<p>0 =&gt; character is not blank<\/p>\n<p><strong> Description: <\/strong>This function checks if the given character is a blank or not. Blank character is a space character that is used to separate words in a line of text.<\/p>\n<p>In C++, the locale-specific version of isblank function exists in &lt;locale&gt;.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong> Example:<\/strong><\/span><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">#include &lt;iostream&gt;\r\n#include &lt;cctype&gt;\r\nusing namespace std;\r\nint main()\r\n{\r\n    char ch_alpha&#x5B;6] = &quot;s t h&quot;; \r\n  \r\n    for (int i=0; i&lt;6; i++) \r\n    { \r\n        if (isblank(ch_alpha&#x5B;i])) \r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is a blank&quot; &lt;&lt; endl; \r\n        else\r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is not a blank&quot; &lt;&lt; endl; \r\n    } \r\n    cout &lt;&lt; endl; \r\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/3.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-104428\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/3.png\" alt=\"Isblank output\" width=\"216\" height=\"176\" \/><\/a><\/p>\n<p>Note the last line in the output which says \u201c is not blank\u201d. This is because of the character array\u2019s last position that is not initialized to a value but still has a printing position. Hence it is not a blank.<\/p>\n<h3><span style=\"color: #ff6600;\">Iscntrl<\/span><\/h3>\n<p><strong> Function Prototype:<\/strong> int iscntrl(int c);<\/p>\n<p><strong> Parameter(s): <\/strong>c=&gt; Character to be checked<\/p>\n<p><strong> Return Value:<\/strong><\/p>\n<p>non-zero=&gt; c is control character<\/p>\n<p>0=&gt; c is not control character<\/p>\n<p><strong> Description: <\/strong>Function checks if the given parameter is a control character. A control character is a character that does not appear in the display or does not occupy a printing position.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong> Example:<\/strong><\/span><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">#include &lt;iostream&gt;\r\n#include &lt;cctype&gt;\r\nusing namespace std;\r\nint main()\r\n{\r\n    char ch_alpha&#x5B;6] = &quot;s\\nt\\th&quot;; \r\n  \r\n    for (int i=0; i&lt;6; i++) \r\n    { \r\n        if (iscntrl(ch_alpha&#x5B;i])) \r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is a control character&quot; &lt;&lt; endl; \r\n        else\r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is not a control character&quot; &lt;&lt; endl; \r\n    } \r\n    cout &lt;&lt; endl; \r\n}<\/pre>\n<p><strong> Output:<\/strong><\/p>\n<p><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/4.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-104429\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/4.png\" alt=\"Iscntrl\" width=\"318\" height=\"206\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/4.png 318w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/4-300x194.png 300w\" sizes=\"(max-width: 318px) 100vw, 318px\" \/><\/a><\/p>\n<h3><span style=\"color: #ff6600;\">Isdigit<\/span><\/h3>\n<p><strong> Function Prototype:<\/strong> int isdigit(int c)<\/p>\n<p><strong> Parameter(s): <\/strong>c=&gt; A character casted to int whose value is to be checked.<\/p>\n<p><strong> Return Value:<\/strong> non-zero =&gt; c is decimal digit<\/p>\n<p>0=&gt; c is not a digit<\/p>\n<p><strong> Description: <\/strong>This function checks if the given parameter is a decimal digit or not. A character is a decimal digit if its value is between 0 and 9.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong> Example:<\/strong><\/span><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">#include &lt;iostream&gt;\r\n#include &lt;cctype&gt;\r\nusing namespace std;\r\nint main()\r\n{\r\n    char ch_alpha&#x5B;5] = &quot;a12b&quot;; \r\n  \r\n    for (int i=0; i&lt;5; i++) \r\n    { \r\n        if (isdigit(ch_alpha&#x5B;i])) \r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is a digit&quot; &lt;&lt; endl; \r\n        else\r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is not a digit&quot; &lt;&lt; endl; \r\n    } \r\n    cout &lt;&lt; endl; \r\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/5.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-104441\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/5.png\" alt=\"Isdigit\" width=\"215\" height=\"142\" \/><\/a><\/p>\n<h3><span style=\"color: #ff6600;\">Isgraph<\/span><\/h3>\n<p><strong> Function Prototype: <\/strong>int isgraph(int c)<\/p>\n<p><strong> Parameter(s): <\/strong>c=&gt; Character casted int that is checked using the isgraph function<\/p>\n<p><strong> Return Value: <\/strong><\/p>\n<p>non-zero=&gt; c is a graphical representation<\/p>\n<p>0=&gt; c is not a graphical representation<\/p>\n<p><strong> Description: <\/strong>Function checks if the given character c is a character with graphical representation. A character that can be printed is a character with graphical representation.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong> Example:<\/strong><\/span><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">#include &lt;iostream&gt;\r\n#include &lt;cctype&gt;\r\nusing namespace std;\r\nint main()\r\n{\r\n    char ch_alpha&#x5B;6] = &quot;a~12b&quot;; \r\n  \r\n    for (int i=0; i&lt;6; i++) \r\n    { \r\n        if (isgraph(ch_alpha&#x5B;i])) \r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is a graphical character&quot; &lt;&lt; endl; \r\n        else\r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is not a graphical character&quot; &lt;&lt; endl; \r\n    } \r\n    cout &lt;&lt; endl; \r\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/6.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-104442\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/6.png\" alt=\"Isgraph\" width=\"295\" height=\"173\" \/><\/a><\/p>\n<h3><span style=\"color: #ff6600;\">Islower<\/span><\/h3>\n<p><strong> Function Prototype:<\/strong> int islower(int c)<\/p>\n<p><strong> Parameter(s): <\/strong>c=&gt; Character that is to be checked using the islower function.<\/p>\n<p><strong> Return Value:<\/strong><\/p>\n<p>non-zer0=&gt; c is lowercase<\/p>\n<p>0=&gt; c is not lowercase<\/p>\n<p><strong> Description: <\/strong>The function islower checks if the given character c is lowercase or not.<\/p>\n<p>A lowercase character is the one that has one of the values: a b c d e f g h I j k l m n o p q r s t u v w x y z.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong> Example:<\/strong><\/span><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">#include &lt;iostream&gt;\r\n#include &lt;cctype&gt;\r\nusing namespace std;\r\nint main()\r\n{\r\n    char ch_alpha&#x5B;4] = &quot;Sth&quot;; \r\n  \r\n    for (int i=0; i&lt;4; i++) \r\n    { \r\n        if (islower(ch_alpha&#x5B;i])) \r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is a lowercase character&quot; &lt;&lt; endl; \r\n        else\r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is not a lowercase character&quot; &lt;&lt; endl; \r\n    } \r\n    cout &lt;&lt; endl; \r\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/7.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-104443\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/7.png\" alt=\"Islower\" width=\"286\" height=\"109\" \/><\/a><\/p>\n<h3><span style=\"color: #ff6600;\">Isprint<\/span><\/h3>\n<p><strong> Function Prototype:<\/strong> int isprint(int c)<\/p>\n<p><strong> Parameter(s):<\/strong> c=&gt; Character that is to be checked using isprint function.<\/p>\n<p><strong> Return Value:<\/strong><\/p>\n<p>non-zer0=&gt; c is printable<\/p>\n<p>0=&gt; c is not printable<\/p>\n<p><strong> Description: <\/strong>Function isprint checks if the given character is printable. A printable character is the one that occupies a printing position in the display.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong> Example:<\/strong><\/span><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">#include &lt;iostream&gt;\r\n#include &lt;cctype&gt;\r\nusing namespace std;\r\nint main()\r\n{\r\n    char ch_alpha&#x5B;4] = &quot;Sth&quot;; \r\n  \r\n    for (int i=0; i&lt;4; i++) \r\n    { \r\n        if (isprint(ch_alpha&#x5B;i])) \r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is a printable character&quot; &lt;&lt; endl; \r\n        else\r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is not a printable character&quot; &lt;&lt; endl; \r\n    } \r\n    cout &lt;&lt; endl; \r\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/8.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-104446\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/8.png\" alt=\"Isprint\" width=\"290\" height=\"111\" \/><\/a><\/p>\n<h3><span style=\"color: #ff6600;\">Ispunct<\/span><\/h3>\n<p><strong> Function Prototype:<\/strong> int ispunct(int c)<\/p>\n<p><strong> Parameter(s):<\/strong> c=&gt; Character that is to be checked using the ispunct function.<\/p>\n<p><strong> Return Value:<\/strong><\/p>\n<p>non-zer0=&gt; c is a punctuation character<\/p>\n<p>0=&gt; c is not punctuation character<\/p>\n<p><strong> Description: <\/strong>This function checks if the given character is a punctuation character. A character that is a graphical character (from isgraph) and not an alphanumeric (from isalnum) is said to be a punctuation character.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong> Example:<\/strong><\/span><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">#include &lt;iostream&gt;\r\n#include &lt;cctype&gt;\r\nusing namespace std;\r\nint main()\r\n{\r\n    char ch_alpha&#x5B;8] = &quot;sth@123&quot;; \r\n  \r\n    for (int i=0; i&lt;8; i++) \r\n    { \r\n        if (ispunct(ch_alpha&#x5B;i])) \r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is a punctuation character&quot; &lt;&lt; endl; \r\n        else\r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is not a punctuation character&quot; &lt;&lt; endl; \r\n    } \r\n    cout &lt;&lt; endl; \r\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/9.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-104447\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/9.png\" alt=\"Ispunct\" width=\"335\" height=\"236\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/9.png 335w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/9-300x211.png 300w\" sizes=\"(max-width: 335px) 100vw, 335px\" \/><\/a><\/p>\n<h3><span style=\"color: #ff6600;\">Isspace<\/span><\/h3>\n<p><strong> Function Prototype:<\/strong> int isspace(int c)<\/p>\n<p><strong> Parameter(s):<\/strong> c=&gt; Character that is to be checked using the isspace function.<\/p>\n<p><strong> Return Value:<\/strong><\/p>\n<p>non-zer0=&gt; c is a white-space<\/p>\n<p>0=&gt; c is not white-space<\/p>\n<p><strong> Description:<\/strong> This function checks if the given character is a white space. For the \u201cC\u201d locale, white-space characters are any of the following.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong> Example:<\/strong><\/span><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">#include &lt;iostream&gt;\r\n#include &lt;cctype&gt;\r\nusing namespace std;\r\nint main()\r\n{\r\n    char ch_alpha&#x5B;7] = &quot;s\\tt\\rh&quot;; \r\n  \r\n    for (int i=0; i&lt;7; i++) \r\n    { \r\n        if (isspace(ch_alpha&#x5B;i])) \r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is a white space&quot; &lt;&lt; endl; \r\n        else\r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is not a white space&quot; &lt;&lt; endl; \r\n    } \r\n    cout &lt;&lt; endl; \r\n}<\/pre>\n<p><strong> Output:<\/strong><\/p>\n<p><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/10.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-104448\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/10.png\" alt=\"Isspace\" width=\"311\" height=\"202\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/10.png 311w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/10-300x195.png 300w\" sizes=\"(max-width: 311px) 100vw, 311px\" \/><\/a><\/p>\n<h3><span style=\"color: #ff6600;\">Isupper<\/span><\/h3>\n<p><strong> Function Prototype:<\/strong> int isupper(int c)<\/p>\n<p><strong> Parameter(s):<\/strong> c=&gt; Character that is to be checked using isupper function.<\/p>\n<p><strong> Return Value:<\/strong><\/p>\n<p>non-zer0=&gt; c is uppercase<\/p>\n<p>0=&gt; c is not uppercase<\/p>\n<p><strong> Description:<\/strong> The functions islower checks if the given character c is uppercase or not.<\/p>\n<p>An uppercase character is the one that has one of the values: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong> Example:<\/strong><\/span><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">#include &lt;iostream&gt;\r\n#include &lt;cctype&gt;\r\nusing namespace std;\r\nint main()\r\n{\r\n    char ch_alpha&#x5B;4] = &quot;STh&quot;; \r\n  \r\n    for (int i=0; i&lt;4; i++) \r\n    { \r\n        if (isupper(ch_alpha&#x5B;i])) \r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is an uppercase character&quot; &lt;&lt; endl; \r\n        else\r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is not an uppercase character&quot; &lt;&lt; endl; \r\n    } \r\n    cout &lt;&lt; endl; \r\n}<\/pre>\n<p><strong> Output:<\/strong><\/p>\n<p><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/11.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-104449\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/11.png\" alt=\"Isupper\" width=\"318\" height=\"110\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/11.png 318w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/11-300x104.png 300w\" sizes=\"(max-width: 318px) 100vw, 318px\" \/><\/a><\/p>\n<h3><span style=\"color: #ff6600;\">Isxdigit<\/span><\/h3>\n<p><strong>Function Prototype:<\/strong> int isxdigit(int c)<\/p>\n<p><strong> Parameter(s):<\/strong> c=&gt; Character that is to be checked using isxdigit function.<\/p>\n<p><strong> Return Value:<\/strong><\/p>\n<p>non-zer0=&gt; c is hexadecimal<\/p>\n<p>0=&gt; c is not a hexadecimal<\/p>\n<p><strong> Description: <\/strong>This function checks if the given character is a hexadecimal digit. Valid hexadecimal digits are 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F<\/p>\n<p><span style=\"text-decoration: underline;\"><strong> Example:<\/strong><\/span><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">#include &lt;iostream&gt;\r\n#include &lt;cctype&gt;\r\nusing namespace std;\r\nint main()\r\n{\r\n    char ch_alpha&#x5B;6] = &quot;sbc10&quot;; \r\n  \r\n    for (int i=0; i&lt;6; i++) \r\n    { \r\n        if (isxdigit(ch_alpha&#x5B;i])) \r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is hexadecimal digit&quot; &lt;&lt; endl; \r\n        else\r\n            cout &lt;&lt; ch_alpha&#x5B;i] &lt;&lt; &quot; is not hexadecimal digit&quot; &lt;&lt; endl; \r\n    } \r\n    cout &lt;&lt; endl; \r\n}<\/pre>\n<p><strong> Output:<\/strong><\/p>\n<p><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/12.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-104450\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/12.png\" alt=\"Isxdigit\" width=\"328\" height=\"174\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/12.png 328w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/12-300x159.png 300w\" sizes=\"(max-width: 328px) 100vw, 328px\" \/><\/a><\/p>\n<h3><span style=\"color: #ff6600;\">tolower<\/span><\/h3>\n<p><strong> Function Prototype: <\/strong>int tolower(int c)<\/p>\n<p><strong> Parameter(s): <\/strong>c=&gt; Character that is to be converted to lowercase.<\/p>\n<p><strong> Return Value: <\/strong><\/p>\n<p>returns the lower equivalent of c, unchanged otherwise.<\/p>\n<p>The return value is int and can be implicitly cast to char.<\/p>\n<p><strong> Description: <\/strong>This converts the given character c into its lowercase equivalent. If the conversion is not possible for a given character, then the unchanged value (c) is returned.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong> Example:<\/strong><\/span><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">#include &lt;iostream&gt;\r\n#include &lt;cctype&gt;\r\nusing namespace std;\r\nint main()\r\n{\r\n    char ch_alpha&#x5B;4] = &quot;STH&quot;; \r\n  \r\n    cout&lt;&lt;ch_alpha&lt;&lt;&quot; converted to lowercase:&quot;;\r\n    for (int i=0; i&lt;4; i++) \r\n    { \r\n        cout&lt;&lt;(char)tolower(ch_alpha&#x5B;i]);\r\n    } \r\n    cout &lt;&lt; endl; \r\n}<\/pre>\n<p><strong> Output:<\/strong><\/p>\n<p>STH\u00a0converted\u00a0to\u00a0lowercase:sth<\/p>\n<h3><span style=\"color: #ff6600;\">toupper<\/span><\/h3>\n<p><strong> Function Prototype:<\/strong> int toupper(int c)<\/p>\n<p><strong> Parameter(s): <\/strong>c=&gt;character that is to be converted to uppercase<\/p>\n<p><strong> Return Value:<\/strong><\/p>\n<p>returns the upper equivalent of c, unchanged otherwise.<\/p>\n<p>The return value is int and can be implicitly cast to char.<\/p>\n<p><strong> Description:<\/strong> This converts the given character c into its uppercase equivalent. If a conversion is not possible for a given character, then the unchanged value (c) is returned.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong> Example:<\/strong><\/span><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">#include &lt;iostream&gt;\r\n#include &lt;cctype&gt;\r\nusing namespace std;\r\nint main()\r\n{\r\n    char ch_alpha&#x5B;10] = &quot;tutorials&quot;; \r\n  \r\n    cout&lt;&lt;ch_alpha&lt;&lt;&quot; converted to lowercase:&quot;;\r\n    for (int i=0; i&lt;10; i++) \r\n    { \r\n        cout&lt;&lt;(char)toupper(ch_alpha&#x5B;i]);\r\n    } \r\n    cout &lt;&lt; endl; \r\n}<\/pre>\n<p><strong><em> Output:<\/em><\/strong><\/p>\n<p>tutorials converted to lowercase: TUTORIALS<\/p>\n<h2>Conclusion<\/h2>\n<p>This ends our tutorial on Character functions in C++.<\/p>\n<p>In this tutorial, we have seen various functions that take a single character and then either classify them or convert them. In our subsequent tutorials, we will discuss string and their functions and classes related to C++.<\/p>\n<p><strong>=&gt; <a href=\"https:\/\/www.softwaretestinghelp.com\/cpp-tutorials\/\">Discover The Simple C++ Training Series Here.<\/a><\/strong><\/p>\n\r\n\t\t\t<div id=\"daexthefup-container\"\r\n\t\t\t\tclass=\"daexthefup-container daexthefup-layout-stacked daexthefup-alignment-center\"\r\n\t\t\t\tdata-post-id=\"104374\">\r\n\r\n\t\t\t\t<div class=\"daexthefup-feedback\">\r\n\t\t\t\t\t<div class=\"daexthefup-text\">\r\n\t\t\t\t\t\t<h3 class=\"daexthefup-title\">Was this helpful?<\/h3>\r\n\t\t\t\t\t<\/div>\r\n\t\t\t\t\t<div class=\"daexthefup-buttons-container\">\r\n\t\t\t\t\t\t<div class=\"daexthefup-buttons\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t<div class=\"daexthefup-yes daexthefup-button daexthefup-button-type-icon\" data-value=\"1\">\r\n\t\t\t\t\r\n                <svg>\r\n                    <defs>\r\n                        <style>.thumb-up-cls-1{fill:#c9c9c9;}.thumb-up-cls-2{fill:#e1e1e1;}.thumb-up-cls-3{fill:#676767;}<\/style>\r\n                    <\/defs>\r\n                    <g id=\"thumb_up\">\r\n                        <path class=\"thumb-up-cls-2 daexthefup-icon-circle\" d=\"m24,3c11.58,0,21,9.42,21,21s-9.42,21-21,21S3,35.58,3,24,12.42,3,24,3m0-1C11.85,2,2,11.85,2,24s9.85,22,22,22,22-9.85,22-22S36.15,2,24,2h0Z\" \/>\r\n                        <g>\r\n                            <rect class=\"thumb-up-cls-3 daexthefup-icon-secondary-color\" x=\"10\" y=\"20\" width=\"6\" height=\"15\" rx=\"1.5\" ry=\"1.5\" \/>\r\n                            <path class=\"thumb-up-cls-1 daexthefup-icon-primary-color\" d=\"m30.57,9.06l-.49-.1c-.81-.17-1.61.35-1.78,1.16l-5.3,11.74c-.17.81,3.16,1.61,3.97,1.78l1.96.41c.81.17,1.61-.35,1.78-1.16l2.18-10.27c.34-1.61-.7-3.21-2.31-3.56Z\" \/>\r\n                            <path class=\"thumb-up-cls-1 daexthefup-icon-primary-color\" d=\"m38.17,20h-18.67c-.83,0-1.5.67-1.5,1.5v12c0,.83.67,1.5,1.5,1.5h16.27c.71,0,1.33-.5,1.47-1.21l2.4-12c.19-.93-.53-1.8-1.47-1.8Z\" \/>\r\n                        <\/g>\r\n                    <\/g>\r\n                <\/svg>\t\t\t<\/div>\r\n\r\n\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t<div class=\"daexthefup-no daexthefup-button daexthefup-button-type-icon\" data-value=\"0\">\r\n\t\t\t\t\r\n                <svg>\r\n                    <defs>\r\n                        <style>.thumb-down-cls-1{fill:#c9c9c9;}.thumb-down-cls-2{fill:#e1e1e1;}.thumb-down-cls-3{fill:#676767;}<\/style>\r\n                    <\/defs>\r\n                    <g id=\"thumb_down\">\r\n                        <path class=\"thumb-down-cls-2 daexthefup-icon-circle\" d=\"m24,3c11.58,0,21,9.42,21,21s-9.42,21-21,21S3,35.58,3,24,12.42,3,24,3m0-1C11.85,2,2,11.85,2,24s9.85,22,22,22,22-9.85,22-22S36.15,2,24,2h0Z\" \/>\r\n                        <g>\r\n                            <rect class=\"thumb-down-cls-3 daexthefup-icon-secondary-color\" x=\"10\" y=\"13\" width=\"6\" height=\"15\" rx=\"1.5\" ry=\"1.5\" \/>\r\n                            <path class=\"thumb-down-cls-1 daexthefup-icon-primary-color\" d=\"m30.57,38.94l-.49.1c-.81.17-1.61-.35-1.78-1.16l-5.3-11.74c-.17-.81,3.16-1.61,3.97-1.78l1.96-.41c.81-.17,1.61.35,1.78,1.16l2.18,10.27c.34,1.61-.7,3.21-2.31,3.56Z\" \/>\r\n                            <path class=\"thumb-down-cls-1 daexthefup-icon-primary-color\" d=\"m38.17,28h-18.67c-.83,0-1.5-.67-1.5-1.5v-12c0-.83.67-1.5,1.5-1.5h16.27c.71,0,1.33.5,1.47,1.21l2.4,12c.19.93-.53,1.8-1.47,1.8Z\" \/>\r\n                        <\/g>\r\n                    <\/g>\r\n                <\/svg>\t\t\t<\/div>\r\n\r\n\t\t\t\t\t\t\t\t\t<\/div>\r\n\t\t\t\t\t<\/div>\r\n\t\t\t\t<\/div>\r\n\r\n\t\t\t\t<div class=\"daexthefup-comment\">\r\n\t\t\t\t\t<div class=\"daexthefup-comment-top-container\">\r\n\t\t\t\t\t\t<label id=\"daexthefup-comment-label\" class=\"daexthefup-comment-label\"><\/label>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"daexthefup-comment-character-counter-container\">\r\n\t\t\t\t\t\t\t\t<div id=\"daexthefup-comment-character-counter-number\"\r\n\t\t\t\t\t\t\t\t\tclass=\"daexthefup-comment-character-counter-number\"><\/div>\r\n\t\t\t\t\t\t\t\t<div class=\"daexthefup-comment-character-counter-text\"><\/div>\r\n\t\t\t\t\t\t\t<\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t<\/div>\r\n\t\t\t\t\t<textarea id=\"daexthefup-comment-textarea\" class=\"daexthefup-comment-textarea\"\r\n\t\t\t\t\t\t\t\tplaceholder=\"Type your message\"\r\n\t\t\t\t\t\t\t\tmaxlength=\"\r\n\t\t\t\t\t\t\t\t400\t\t\t\t\t\t\t\t\t\"><\/textarea>\r\n\t\t\t\t\t<div class=\"daexthefup-comment-buttons-container\">\r\n\t\t\t\t\t\t<button class=\"daexthefup-comment-submit daexthefup-button\">Submit<\/button>\r\n\t\t\t\t\t\t<button class=\"daexthefup-comment-cancel daexthefup-button\">Cancel<\/button>\r\n\t\t\t\t\t<\/div>\r\n\t\t\t\t<\/div>\r\n\r\n\t\t\t\t<div class=\"daexthefup-successful-submission-text\">Thanks for your feedback!<\/div>\r\n\r\n\t\t\t<\/div>\r\n\r\n\t\t\t","protected":false},"excerpt":{"rendered":"<p>This Tutorial Explains C++ Character &amp; Transformation Functions with Examples. Some Important Functions Covered are isdigit, islower, isupper, isalpha etc.: In our previous tutorial on \u201clibrary functions\u201d, we saw the various headers that provide numerous functions that operate on different data types. The header &lt;cctype.h&gt; is one such header that &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"C++ Character Classification And Tranformation Functions\" class=\"read-more button\" href=\"https:\/\/www.softwaretestinghelp.com\/cpp-character-functions\/#more-104374\" aria-label=\"Read more about C++ Character Classification And Tranformation Functions\">Read more<\/a><\/p>\n","protected":false},"author":9,"featured_media":104880,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_helpful_pro_status":1,"footnotes":""},"categories":[403],"tags":[],"class_list":{"0":"post-104374","1":"page","2":"type-page","3":"status-publish","4":"has-post-thumbnail","6":"category-cpp"},"acf":[],"_links":{"self":[{"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/pages\/104374","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/comments?post=104374"}],"version-history":[{"count":0,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/pages\/104374\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/media\/104880"}],"wp:attachment":[{"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/media?parent=104374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/categories?post=104374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/tags?post=104374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}