Spaces to Underscores | Sololearn: Learn to code for FREE!

+1

Spaces to Underscores

Hey everyone, I just have a quick question I'm trying to code something in c programming, where I have to ask the user for a string, change all the spaces inside that string to an underscore. And print both strings on the console. So I'm not allowed to change the first string. Does anyone have a suggestions for me on how to do so? I'm supposed to implement pointers as well. Thank you

4/16/2020 8:02:34 AM

Gursher Singh

2 Answers

New Answer

+7

Make a new variable and store the value of string in it. Now you can make changes in the old variable without disturbing new one. And you will be able to use both of the strings.

0

copy the string char by char to another location (another variable), and while iteration, replace the spaces encountered by underscores ;)