I am trying to make an upper case key and a lower case key of the one typed by the user but when I use the toupper and tolower functions they turn all my chars into lower or upper. Not just the one I want. Valkey is the key the user typed. If they type VBnmdG, I get vbNMDg for all three strings instead of the original untouched, the upper in all uppers and the lower in all lowers.
string key_upper = valkey;
string key_lower = valkey;
for (int i = 0; i < len; i++)
{
if (isalpha(valkey[i]) == 0)
{
printf("Key must only contain alphabetic characters.\n");
return 1;
}
if (isupper(valkey[i]))
{
key_lower[i] = tolower(key_lower[i]);
}
else if (islower(valkey[i]))
{
key_upper[i] = toupper(key_upper[i]);
}
else
continue;
}
printf("valkey: %s\n", valkey);
printf("keyupper: %s\n", key_upper);
printf("keylower: %s\n", key_lower);