convert string from upper cas to lower case 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: convert string to lowercase in c
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
int main(int argc, string argv[])
{
if (argc != 2)
{
printf("Usage: ./substitution key\n");
}
else if (strlen(argv[1]) != 26)
{
printf("Key must contain 26 characters.\n");
}
string key = argv[1].toupper();
string key = argv[1].tolower();
}