[Solved] How to add space between every characters using C


The shorter, more general answer is that you need to bump characters back, and insert a ‘ ‘ in between them. What have you done so far? Does it need to be in place?

One (perhaps not optimal, but easy to follow solution) would be making a larger array, copying in alternating letters, something like (not guaranteed to work verbatim)

char foo[N]; // assuming this has N characters and you want to add a space in between all of them.
char bar[2*N];
for (int i = 0; i < N; i++) {
    bar[2*i] = foo[i];
    if (i != N - 1)
        bar[2*i + 1] = ' ';
}

Of course, this new string is in bar, but functions as desired. At what point are you having issues?

6

solved How to add space between every characters using C