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|

```
```
char** list

```

Isn't a 'array of bytes' its a 'pointer to a pointer pointing to char' which you can think of as a 'list of lists of char'. Also if you define it this way, you need to malloc enough memory to hold the data.

When you write:

```
list[i] = 'a';

```

Its messing up memory because your placing a char 'a' in a location specified to hold a pointer. Actually in most compilers character literals are of type int so your actually storing an int form of 'a' as a pointer to a memory location which can cause all sorts of memory corruption. 

If you want 'list' to be on the stack then define it as:

```
char list[20]

```

If you want 'list' to be in the heap then define it as:

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

```

In either case access it as:

```
list[i]

```

Also its not safe to assume the size of int being equivalent to the size of a pointer as you to have done in your second example. At least i think thats what you were trying to do. 

Additionally if your storing raw bytes from a data stream or something of that sort you should likely be using 'unsigned char' not 'char' and for more safety use 'int8\_t' as you can't always guarantee that 'char' is 8 bits although it is on the majority of platforms.