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';

```
This is one way to do what you want - since you know that the two indexes in `str_out` that you want to access correspond to the `i`th and `i+1`th positions of `str_in`:

```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define SIZE    100

int main(void)
{
    char str_in[SIZE];
    char str_out[SIZE*2];
    int i, len;

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

    for (i = 0; i < len; i++) {
        str_out[i*2] = str_in[i];
        str_out[i*2+1] = str_in[i];
    }
    str_out[i*2] = '\0';

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

    return EXIT_SUCCESS;
}

```

You could also use another variable and update inside the loop as such:

```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define SIZE    100

int main(void)
{
    char str_in[SIZE];
    char str_out[SIZE*2];
    int i, j, len;

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

    for (i = 0, j = 0; i < len; i++, j += 2) {
        str_out[j] = str_in[i];
        str_out[j+1] = str_in[i];
    }
    str_out[j] = '\0';

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

    return EXIT_SUCCESS;
}

```

As a side note, it's best to `#define` your constants instead of having them in your code.