C Program To Convert String into Uppercase Characters
Learn How To Convert String into Uppercase Characters in C Programming Language. This C Program demonstrates the use of Library Functions toupper() method.
The toupper() method is defined in the ctype.h header file. The strlen() method is defined in the string.h header file. The second method makes use of ASCII value conversion. The toupper() method converts the character into its corresponding Uppercase letter.
Must Read: C Program To Remove Vowels from String
C Program To Convert String into Uppercase using Library Functions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include<stdio.h> #include<ctype.h> #include<string.h> int main() { int count = 0, length = 0; char str[100]; printf("\nEnter A String:\t"); scanf("%s", str); printf("\nOriginal String:\t%s\n", str); length = strlen(str); while(count < length) { str[count] = toupper(str[count]); count++; } printf("\nAfter Character Conversion\n"); printf("\nNew String:\t%s\n", str); return 0; } |
Must Read: C Program For Conversion of String into Lowercase Characters
C Program For String Conversion into Uppercase without toupper() method (ASCII Values)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include<stdio.h> #include<ctype.h> #include<string.h> int main() { int count, length = 0; char str[100]; printf("\nEnter A String:\t"); scanf("%s", str); printf("\nOriginal String:\t%s\n", str); length = strlen(str); for(count = 0; count < length; count++) { if(str[count] >= 65 && str[count] <= 90) { continue; } else { str[count] = str[count] - 32; } } printf("\nAfter Character Conversion\n"); printf("\nNew String:\t%s\n", str); return 0; } |
Must Read: C Program To Convert String Character From Uppercase To Lowercase and Vice versa
Output

In case you get any Compilation Errors or any doubts in this C Program To Convert String into Uppercase letters with and without String Library Functions, let us know about it in the Comment Section below.
Is it necessary to use strlen method to find the length of the string? Can’t we use the array limit 100 in the for loop instead of using length?
Hi Ajay! You can use the limit of array which is 100 in this program. But, instead of incrementing the For Loop till 100, you can reduce the execution time by incrementing the counter variable in the for loop till the String’s Length. If the String’s length is only 20, the loop will go till 100 which is a waste of time and space. The strlen() method will automatically fetch the exact length even if it is 90 (still saving you from 9 loops).