+ 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

16th Apr 2020, 8:02 AM
Gursher Singh
2 Answers
+ 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.
16th Apr 2020, 8:07 AM
Shreyansh
Shreyansh - avatar
0
copy the string char by char to another location (another variable), and while iteration, replace the spaces encountered by underscores ;)
16th Apr 2020, 3:46 PM
visph
visph - avatar