c - Insert "E" after "T" in a string w/o tempering with "T" -


the goal insert "e" after occurrences of letter "t"

but code below does:

soon character "t" detected...

it replaces "t" "t" inserts "e"

how can altered not replace "t" "t" because seems work.

instead can leave alone existing "t" in place.. move after , insert "e".

char s1[1024]; int i, n;    (i=0, n = 0; s[i]!= '\0'; i++)   {     if (s[i] == 't')     {             s1[n] = 't';             n++;             s1[n] = 'e';             n++;     }     else     {         s1[n] = s[i];         n++;     } } s1[n] = '\0'; 

just copy characters , when see have copied t, copy e

s1[n] = s[i]; n++;     if (s[i] == 't') {   s1[n] = 'e';   n++; } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -