Making a String Lowercase

Hello! I am trying to write a function that takes a string for an argument and changes that string into all lower case. However, when I run this program, it outputs the original string lower cased, and then my original string with the capitalization. For example, if I were to input "ASDf", the string, user_input, will now hold "asdfASDf". Any idea how to fix this?

1
2
3
4
5
6
7
8
9
void makeLowerCase(string& user_input) {
	int i = 0; 
	char c;
	while (user_input[i]) {
		c = user_input[i]; 
		putchar(tolower(c));
		i++;
	}
}
Last edited on
1
2
3
4
5
6
7
8
9
void makeLowerCase(string& user_input) {
	int i = 0; 
	char c;
	while (user_input[i]) { //Technically illegal. Use for(int i = 0; i < user_input.size(); ++i)
		c = user_input[i]; 
		putchar(tolower(c)); //Just outputs lowercase character to the screen, does not saves it to string
		i++;
	}
}
Your function is actually show_lowercase as it shows passed string in lowercase and do not change it.
@MiiNiPaa

OOOOO... I see... Thank you for your help. I'm going to try to figure out a way to store into a string :) Thank you again!

Best, Jae Kim

Topic archived. No new replies allowed.