0

Is there a way to replace all occurrences of a word in a string in C with another word. By word, I don't mean substring.

Here's what I want to achieve:

Input String:

OneOne One One OneOneOne One

Word to find:

One

Word to Replace it with:

Forty

Desired Output:

OneOne Forty Forty OneOneOne Forty
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • 3
    Please take some time to read [the help pages](http://stackoverflow.com/help), especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). Also please [take the tour](http://stackoverflow.com/tour) and [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask). Lastly please learn how to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve). – Some programmer dude Oct 06 '17 at 03:50

1 Answers1

0

there are many example functions for replacing words in a string, i.e. What is the function to replace string in C?

you can use these functions to do what you want because the (white)spaces are also characters, see Removing Spaces from a String in C? and https://www.cs.tut.fi/~jkorpela/chars/spaces.html

so in the replace functions it is a difference if the replace string is

replace ='One' or replace = ' One '

if you use the second this should work

https://en.wikipedia.org/wiki/Whitespace_character

Unicode stored in C char

ralf htp
  • 9,149
  • 4
  • 22
  • 34