{"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[pastacode lang=\u201dc\u201d manual=\u201d%23include%20%3Cstdio.h%3E%0A%23include%20%3Cstring.h%3E%0A%20%0Aint%20main()%0A%7B%0A%20%20%20char%20string%5B1000%5D%3B%0A%20%0A%20%20%20printf(%22Input%20a%20string%20to%20convert%20to%20lower%20case%5Cn%22)%3B%0A%20%20%20gets(string)%3B%0A%20%0A%20%20%20printf(%22Input%20string%20in%20lower%20case%3A%20%5C%22%25s%5C%22%5Cn%22%2Cstrlwr(string))%3B%0A%20%0A%20%20%20return%20%200%3B%0A%7D\u201d message=\u201d\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n[ad type=\u201dbanner\u201d]\n<h2 id=\"strupr-in-c\">strupr in c<\/h2>\n[pastacode lang=\u201dc\u201d manual=\u201d%23include%20%3Cstdio.h%3E%0A%23include%20%3Cstring.h%3E%0A%20%0Aint%20main()%0A%7B%0A%20%20%20char%20string%5B1000%5D%3B%0A%20%0A%20%20%20printf(%22Input%20a%20string%20to%20convert%20to%20upper%20case%5Cn%22)%3B%0A%20%20%20gets(string)%3B%0A%20%0A%20%20%20printf(%22Input%20string%20in%20upper%20case%3A%20%5C%22%25s%5C%22%5Cn%22%2Cstrupr(string))%3B%0A%20%0A%20%20%20return%20%200%3B%0A%7D\u201d message=\u201d\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n[ad type=\u201dbanner\u201d]\n<h2 id=\"change-string-to-upper-case-without-strupr\">Change string to upper case without strupr<\/h2>\n[pastacode lang=\u201dc\u201d manual=\u201d%23include%20%3Cstdio.h%3E%0A%20%0Avoid%20upper_string(char%20%5B%5D)%3B%0A%20%0Aint%20main()%0A%7B%0A%20%20%20char%20string%5B100%5D%3B%0A%20%0A%20%20%20printf(%22Enter%20a%20string%20to%20convert%20it%20into%20upper%20case%5Cn%22)%3B%0A%20%20%20gets(string)%3B%0A%20%0A%20%20%20upper_string(string)%3B%0A%20%0A%20%20%20printf(%22Entered%20string%20in%20upper%20case%20is%20%5C%22%25s%5C%22%5Cn%22%2C%20string)%3B%0A%20%0A%20%20%20return%200%3B%0A%7D%0A%20%0Avoid%20upper_string(char%20s%5B%5D)%20%7B%0A%20%20%20int%20c%20%3D%200%3B%0A%20%0A%20%20%20while%20(s%5Bc%5D%20!%3D%20\u2019%5C0\u2032)%20%7B%0A%20%20%20%20%20%20if%20(s%5Bc%5D%20%3E%3D%20\u2019a\u2019%20%26%26%20s%5Bc%5D%20%3C%3D%20\u2019z\u2019)%20%7B%0A%20%20%20%20%20%20%20%20%20s%5Bc%5D%20%3D%20s%5Bc%5D%20-%2032%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20c%2B%2B%3B%0A%20%20%20%7D%0A%7D\u201d message=\u201d\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<h2 id=\"change-string-to-lower-case-without-strlwr\">Change string to lower case without strlwr<\/h2>\n[pastacode lang=\u201dc\u201d manual=\u201d%23include%20%3Cstdio.h%3E%0A%20%0Avoid%20lower_string(char%20%5B%5D)%3B%0A%20%0Aint%20main()%0A%7B%0A%20%20%20char%20string%5B100%5D%3B%0A%20%0A%20%20%20printf(%22Enter%20a%20string%20to%20convert%20it%20into%20lower%20case%5Cn%22)%3B%0A%20%20%20gets(string)%3B%0A%20%0A%20%20%20lower_string(string)%3B%0A%20%0A%20%20%20printf(%22Entered%20string%20in%20lower%20case%20is%20%5C%22%25s%5C%22%5Cn%22%2C%20string)%3B%0A%20%0A%20%20%20return%200%3B%0A%7D%0A%20%0Avoid%20lower_string(char%20s%5B%5D)%20%7B%0A%20%20%20int%20c%20%3D%200%3B%0A%20%0A%20%20%20while%20(s%5Bc%5D%20!%3D%20\u2019%5C0\u2032)%20%7B%0A%20%20%20%20%20%20if%20(s%5Bc%5D%20%3E%3D%20\u2019A\u2019%20%26%26%20s%5Bc%5D%20%3C%3D%20\u2019Z\u2019)%20%7B%0A%20%20%20%20%20%20%20%20%20s%5Bc%5D%20%3D%20s%5Bc%5D%20%2B%2032%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20c%2B%2B%3B%0A%20%20%20%7D%0A%7D\u201d message=\u201d\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p>You can also implement functions using pointers.<\/p>\n[ad type=\u201dbanner\u201d]\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[pastacode lang=\u201dc\u201d manual=\u201d%23include%20%3Cstdio.h%3E%0A%20%0Aint%20main%20()%20%0A%7B%0A%20%20%20int%20c%20%3D%200%3B%0A%20%20%20char%20ch%2C%20s%5B1000%5D%3B%0A%20%0A%20%20%20printf(%22Input%20a%20string%5Cn%22)%3B%0A%20%20%20gets(s)%3B%0A%20%0A%20%20%20while%20(s%5Bc%5D%20!%3D%20\u2019%5C0\u2032)%20%7B%0A%20%20%20%20%20%20ch%20%3D%20s%5Bc%5D%3B%0A%20%20%20%20%20%20if%20(ch%20%3E%3D%20\u2019A\u2019%20%26%26%20ch%20%3C%3D%20\u2019Z\u2019)%0A%20%20%20%20%20%20%20%20%20s%5Bc%5D%20%3D%20s%5Bc%5D%20%2B%2032%3B%0A%20%20%20%20%20%20else%20if%20(ch%20%3E%3D%20\u2019a\u2019%20%26%26%20ch%20%3C%3D%20\u2019z\u2019)%0A%20%20%20%20%20%20%20%20%20s%5Bc%5D%20%3D%20s%5Bc%5D%20-%2032%3B%20%20%20%0A%20%20%20%20%20%20c%2B%2B%3B%20%20%20%0A%20%20%20%7D%0A%20%0A%20%20%20printf(%22%25s%5Cn%22%2C%20s)%3B%0A%20%0A%20%20%20return%200%3B%0A%7D\u201d message=\u201d\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\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}]}}