The goal is to insert "E" after all occurrences of the letter "T"
But this is what the code below does:
Soon as the character "T" is detected...
It replaces "T" with another "T" then inserts "E"
How can it be altered so it does not replace "T" with another "T" because it seems like extra work.
Instead it can simply leave alone the existing "T" in place.. move AFTER it and insert the "E".
char s1[1024];
int i, n;
for (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';