title: Replacing Words inside string in C
body: <p>I'm looking for a way to replace word/words in string.
  let's say if i use function like this:</p>
  
  <pre><code>changewords("Hello I'm Number One","Number One","Zero");
  </code></pre>
  
  <p>the output will be like: "Hello I'm Number One" -> "Hello I'm Zero" </p>
  
  <p>but more of then i will able to replace only one word too </p>
  
  <pre><code>changewords("Hello I'm Number One","One","Four");
  </code></pre>
  
  <p>like this: "Hello I'm Number One" -> "Hello I'm Number Four"</p>
  
  <p>In my code i split sentence to words and the compare each word to the word that i need to change, but i able to change only one word in that way, any one can advice how to do it correctly please?
  Thanks.
  Here is my code, it using one line from matrix (table) as a sentence, and the line number is the sentenceToChange variable.</p>
  
  <pre><code>int changewords (char table[][MAX_SENTENCE_LENGTH], int numOfSentences, int sentenceToChange, char subString[],char replaceWith[]){
  int slen,i=0,q=0,c=0;
  char wordlist[100][100];
  char final[1][100];
  slen=strlen(table[sentenceToChange]);
  for(i=0;i&lt;slen;i++) {
      if(table[sentenceToChange][i]!=' '){
          wordlist[q][c]=table[sentenceToChange][i];
      c++;
      }
      else { 
          wordlist[q][c]='\0';
          c=0;
          q++;
      }
  }
  for(i=0;i&lt;q;i++) {
  if (!strcmp(wordlist[i],subString)) {
  strcpy(wordlist[i],replaceWith);
  }
  }
  final[0][0]='\0';
  for(i=0;i&lt;=q;i++) {
  strcat(final[0],wordlist[i]);
  if(i!=q) strcat(final[0]," ");
  }
  final[0][slen-1]='\0';
  strcpy(table[sentenceToChange],final[0]);
  </code></pre>
  
  <p>}</p>