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
Post a Comment