{"id":27217,"date":"2018-01-05T20:32:24","date_gmt":"2018-01-05T15:02:24","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=27217"},"modified":"2018-01-05T20:32:24","modified_gmt":"2018-01-05T15:02:24","slug":"c-program-to-change-case-of-a-string","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/c-program-to-change-case-of-a-string\/","title":{"rendered":"C program to change case of a string"},"content":{"rendered":"<p>Strlwr function convert a <a href=\"https:\/\/www.wikitechy.com\/technology\/substring-in-c-programming\/\">string <\/a>to lower case and strupr function convert a string to upper case.Here we will change string case with and without strlwr, strupr functions. These functions convert case of alphabets and ignore other characters which may be present in a string.<\/p>\n<h2 id=\"strlwr-in-c\">strlwr in c<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-c code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-c code-embed-code\">#include &lt;stdio.h&gt;<br\/>#include &lt;string.h&gt;<br\/> <br\/>int main()<br\/>{<br\/>   char string[1000];<br\/> <br\/>   printf(&quot;Input a string to convert to lower case\\n&quot;);<br\/>   gets(string);<br\/> <br\/>   printf(&quot;Input string in lower case: \\&quot;%s\\&quot;\\n&quot;,strlwr(string));<br\/> <br\/>   return  0;<br\/>}<\/code><\/pre> <\/div>\n[ad type=&#8221;banner&#8221;]\n<h2 id=\"strupr-in-c\">strupr in c<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-c code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-c code-embed-code\">#include &lt;stdio.h&gt;<br\/>#include &lt;string.h&gt;<br\/> <br\/>int main()<br\/>{<br\/>   char string[1000];<br\/> <br\/>   printf(&quot;Input a string to convert to upper case\\n&quot;);<br\/>   gets(string);<br\/> <br\/>   printf(&quot;Input string in upper case: \\&quot;%s\\&quot;\\n&quot;,strupr(string));<br\/> <br\/>   return  0;<br\/>}<\/code><\/pre> <\/div>\n[ad type=&#8221;banner&#8221;]\n<h2 id=\"change-string-to-upper-case-without-strupr\">Change string to upper case without strupr<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-c code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-c code-embed-code\">#include &lt;stdio.h&gt;<br\/> <br\/>void upper_string(char []);<br\/> <br\/>int main()<br\/>{<br\/>   char string[100];<br\/> <br\/>   printf(&quot;Enter a string to convert it into upper case\\n&quot;);<br\/>   gets(string);<br\/> <br\/>   upper_string(string);<br\/> <br\/>   printf(&quot;Entered string in upper case is \\&quot;%s\\&quot;\\n&quot;, string);<br\/> <br\/>   return 0;<br\/>}<br\/> <br\/>void upper_string(char s[]) {<br\/>   int c = 0;<br\/> <br\/>   while (s[c] != &#039;\\0&#039;) {<br\/>      if (s[c] &gt;= &#039;a&#039; &amp;&amp; s[c] &lt;= &#039;z&#039;) {<br\/>         s[c] = s[c] - 32;<br\/>      }<br\/>      c++;<br\/>   }<br\/>}<\/code><\/pre> <\/div>\n<h2 id=\"change-string-to-lower-case-without-strlwr\">Change string to lower case without strlwr<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-c code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-c code-embed-code\">#include &lt;stdio.h&gt;<br\/> <br\/>void lower_string(char []);<br\/> <br\/>int main()<br\/>{<br\/>   char string[100];<br\/> <br\/>   printf(&quot;Enter a string to convert it into lower case\\n&quot;);<br\/>   gets(string);<br\/> <br\/>   lower_string(string);<br\/> <br\/>   printf(&quot;Entered string in lower case is \\&quot;%s\\&quot;\\n&quot;, string);<br\/> <br\/>   return 0;<br\/>}<br\/> <br\/>void lower_string(char s[]) {<br\/>   int c = 0;<br\/> <br\/>   while (s[c] != &#039;\\0&#039;) {<br\/>      if (s[c] &gt;= &#039;A&#039; &amp;&amp; s[c] &lt;= &#039;Z&#039;) {<br\/>         s[c] = s[c] + 32;<br\/>      }<br\/>      c++;<br\/>   }<br\/>}<\/code><\/pre> <\/div>\n<p>You can also implement functions using pointers.<\/p>\n[ad type=&#8221;banner&#8221;]\n<h2 id=\"c-program-to-change-case-from-upper-to-lower-and-lower-to-upper\">C program to change case from upper to lower and lower to upper<\/h2>\n<p>Below program change case of alphabets if a lower case alphabet is found it is converted to upper and if an upper case is found it is converted to lower case.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-c code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-c code-embed-code\">#include &lt;stdio.h&gt;<br\/> <br\/>int main () <br\/>{<br\/>   int c = 0;<br\/>   char ch, s[1000];<br\/> <br\/>   printf(&quot;Input a string\\n&quot;);<br\/>   gets(s);<br\/> <br\/>   while (s[c] != &#039;\\0&#039;) {<br\/>      ch = s[c];<br\/>      if (ch &gt;= &#039;A&#039; &amp;&amp; ch &lt;= &#039;Z&#039;)<br\/>         s[c] = s[c] + 32;<br\/>      else if (ch &gt;= &#039;a&#039; &amp;&amp; ch &lt;= &#039;z&#039;)<br\/>         s[c] = s[c] - 32;   <br\/>      c++;   <br\/>   }<br\/> <br\/>   printf(&quot;%s\\n&quot;, s);<br\/> <br\/>   return 0;<br\/>}<\/code><\/pre> <\/div>\n<p><strong>Output of program:<\/strong><\/p>\n<pre class=\"c geshifilter-c\">Input a string\r\nabcdefghijklmnopqrstuvwxyz{0123456789}ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\nABCDEFGHIJKLMNOPQRSTUVWXYZ{0123456789}abcdefghijklmnopqrstuvwxyz<\/pre>\n<p>If a digit or special character is present in string.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C program to change case of a string &#8211; C Programming &#8211; Strlwr function convert a string to lower case and strupr function convert a string to upper case.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69969,69866],"tags":[81136,81138,81139,81133,81135,81134,81140,81137],"class_list":["post-27217","post","type-post","status-publish","format-standard","hentry","category-algorithm","category-c-programming","tag-c-program-to-convert-lowercase-to-uppercase-and-vice-versa","tag-c-program-to-convert-uppercase-to-lowercase-by-using-file","tag-c-program-to-convert-uppercase-to-lowercase-and-vice-versa","tag-convert-lowercase-to-uppercase-in-c-without-library-function","tag-convert-string-to-lowercase-c-programming","tag-convert-string-to-uppercase-in-c","tag-convert-string-to-uppercase-in-c-without-toupper","tag-strupr-in-c"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/27217","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=27217"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/27217\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=27217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=27217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=27217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}