how to make string uppercase in c code example
Example 1: convert string to uppercase in c
For those of you who want to uppercase a string and store it in a variable (that was what I was looking for when I read these answers).
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void)
{
string s = "I want to cast this";
unsigned long int s_len = strlen(s);
char s_up[s_len];
for (int a = 0; a < s_len; a++)
{
s_up[a] = toupper(s[a]);
}
s = s_up;
printf("%s \n", s_up);
}
Example 2: C string convert All Uppercse To Lowercase
#include <stdio.h>
#include <string.h>
int main() {
char s[100];
int i;
printf("\nEnter a string : ");
gets(s);
for (i = 0; s[i]!='\0'; i++) {
if(s[i] >= 'A' && s[i] <= 'Z') {
s[i] = s[i] + 32;
}
}
printf("\nString in Lower Case = %s", s);
return 0;
}
Example 3: to upper in c
#include <ctype.h>