Convert String from lowercase to uppercase in C CPP Java Python
- C
- CPP
- Python
- Java
#include<stdio.h>
#include<string.h>
int main(){
char str[25];
int i;
printf("Enter the string:");
scanf("%s",str);
/* running the loop from 0 to the length of the string
* to convert each individual char of string to uppercase
* by subtracting 32 from the ASCII value of each char
*/
for(i=0;i<=strlen(str);i++){
/* Here we are performing a check so that only lowercase
* characters gets converted into uppercase.
* ASCII value of a to z(lowercase chars) ranges from 97 to 122
*/
if(str[i]>=97&&str[i]<=122)
str[i]=str[i]-32;
}
printf("\nUpper Case String is: %s",str);
return 0;
}