I have char* myChar = "HELLO". I would like to switch the places of the E and the O. I tried doing myChar[1] = myChar[4], but that doesn’t work. Please help!
I have char* myChar = HELLO . I would like to switch the places
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First off, that string literal is probably being stored in read-only memory. You can fix that by declaring the string as an array of characters:
To swap the characters, you’ll have to use a temporary variable: