Question: I want to write a program where it duplicates every letter in a given string.

For example, if the input is `abc` then the output would be `aabbcc`.

How can I do this?

Here is my code so far. It only copies the string:

```
#include <stdio.h>

int main () {
    char str_in[100];
    char str_out[200] = "";
    int i;

    printf("Enter a word: ");
    scanf("%s", str_in);

    for (i = 0; i < sizeof(str_in); i++) {
        str_out[i] += str_in[i];
    }

    printf("Duplicated word: %s", str_out);

    return 0;
}

```

Answer: 
For starters the destination character array should be at least two times larger than the source array.

The loop that performs the copying can look the following way

```
size_t j = 0;
for ( size_t i = 0; str_in[i] != '\0'; i++ ) 
{
    str_out[j++] = str_in[i];
    str_out[j++] = str_in[i];
}

str_out[j] = '\0';

```
I would suggest only allocating the amount of memory you need:

```
char *str_out = malloc(strlen(str_in) + 1);

```

and then using another loop variable that counts by 2 each time so you have 2 times as much space for every character in your loop.

If you do that, you should also put `+ 1` next to the new loop variable to copy it to the current and next elements of the string, thereby duplicating the characters.

I would also advise you to use `size_t` for your loop variables to match the return of `str_len`.

Here I have implemented my suggestions:

```
size_t str_ctr;
size_t str_ctrx2;
size_t in_str_len = strlen(in_str)
/* ... */
for( str_ctrx2 = str_ctr = 0;
     str_ctr < in_str_len;
     str_ctr++, str_ctrx2 += 2 )
{
    out_str[str_ctrx2] = in_str[str_ctr];
    out_str[str_ctrx2 + 1] = in_str[str_ctr];
}
/* null-terminate the string */
out_str[str_ctrx2] = '\0';

```

I would also like to mention that you forget to null-terminate your string in your program. I have made a comment about that and have shown you how to do it above.