int main(void)
{
string original = "ABCdef";
string upper;
string lower;
for (int i = 0; i < 6; i++)
{
if (isupper(original[i]) > 0)
{
upper[i]= original[i] - 32;
}
else
{
upper[i] = original[i];
}
}
for (int i = 0; i < 6; i++)
{
if (islower(key[i]) > 0)
{
lower_key[i] = key[i] + 32;
}
else
{
lower_key[i] = key[i];
}
}
}
My goal here is to create 2 new strings, upper and lower, that are the uppercase and lowercase versions of original to be used later in my program. When I run the program as it is above the IDE tells me that I must assign upper and lower values before using them.
I have tried assigning NULL to them both at initialisation, as the IDE suggests, but this resulted in an error. When that failed, I tried assigning original to both. This almost worked, but for some reason meant that all three variables were altered when I assigned upper and lower different values within the if functions. This is a problem, as I need to be able to use upper and lower separately later on. Finally, I tried assigning "ABCDEF" to them both, but of course ran into the issue of an "incompatible pointer to integer assigning to 'string'" error.
How should I declare upper and lower in order for them to work as intended?
question from:
https://stackoverflow.com/questions/65830649/how-can-i-assign-value-to-a-string-char-by-char-after-declaration-in-c 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…