Question: I'm trying to write a response into a variable, and I can't figure out how to do it.

This doesn't work - screws up memory, but no protection errors:

```
for (int i = 0; i < 20; i++) {
    list[i] = 'a';
}

```

Same with this - memory screwed up:

```
for (int i = 0; i < 20; i++) {
    *(((int*)(list))+i) = 'a';
}
//I don't think this is a string issues as this doesn't help:
//*(((int*)(list))+20) = '\0';

```

This causes a bus error:

```
for (int i = 0; i < 20; i++) {
    *list[i] = 'a';
}

```

*This works as desired:*

```
*list = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";

```

**What am I doing wrong?**

**P.S.** `list` is `char**`.

Answer: 
In C, a pointer can be used to represent an array, and a single string is an array of `char`, or in other words, a `char *`. This means that a `char **` is an array of strings. So if you want to put characters into the first string (assuming that memory has already been allocated to it), you should use `list[0][i] = 'a';` in the first loop - i.e., put `'a'` into position `i` of the `0`th string.

Another way of interpreting a `char **` (which is the one I suspect is the one you're supposed to use) is that it is a pointer that points to a pointer that points to an array of `char`. In that case, you can use the "outer" pointer to modify what the inner pointer points to; this can be used to first allocate the string and then write to it:

```
*list = malloc(21); // Allocate 21 bytes and make the pointer that 'list' points to refer to that memory
for (int i = 0; i < 20; i++) {
    (*list)[i] = 'a';
}
(*list)[20] = '\0'; // Also, you need the null terminator at the end of the string

```

In memory, this looks like this:

```
list ---> (another pointer) ---> |a|a|a|a|a|a|...|a|a|\0|

```
Since you want an array of bytes then `char**` is wrong – that's a pointer to a pointer to `char`. You want `char*` for an array, but if it's fixed length I'd declare it as `char list[20]`.

It seems like you want to write something like this:

```
char list[20];
for (int i = 0; i < 20; i++) {
    list[i] = 'a';
}

```

Or if you want heap allocation use

```
char *list = malloc(20);

```

---

Since we are reduced to guessing, I think that you meant to say that `*list` is an array of bytes. In which case the code would be like so:

```
char **list = get_list_from_somewhere();
*list = malloc(20);
for (int i = 0; i < 20; i++) {
    *list[i] = 'a';
}

```