string s = get_string();
string s_lower = s;
for (int i = 0, n = strlen(s); i < n; i++)
{
s[i] = toupper(s[i]);
}
for (int i = 0, n = strlen(s_lower); i < n; i++)
{
s_lower[i] = tolower(s_lower[i]);
}
The thing with these lines of code is I don't understand why my string s_lower changes while executing the first loop and the same thing for the second loop. Didn't I create two different variables(strings) ?
string s = get_string();
string s_lower[strlen(s) + 1];
strcpy(s_lower, s);
I'm trying to use strcpy function as it's recommended. But it doesn't work like this. I also tried to initiliaze my string s_lower without any value. Help please ?
Problem fixed:
string s = get_string();
string s_lower;
s_lower = malloc(sizeof strlen(s) + 1);
strcpy(s_lower, s);