I have a struct like this:

```
typedef struct TEXT {
    char *text;
    struct TEXT *next;
} TEXT;

```

and in some function I have something like:

```
TEXT *line = (TEXT *) malloc(sizeof(TEXT));
line->text = NULL; // was "\0" before
char current = getchar();
while (current != '\n') {
    AddChar(&(line->text), current); // Was AddChar(line->text, current);
    current = getchar();
}

```

and the AddChar function was something like this:

```
void AddChar(char **text, char c) { //was char *text
    *text = (char *) realloc(*text, strlen(*text)+2); //was text = ...
    char char_array[2] = {c, '\0'); 
    strcat(*text, char_array); //was strcat(text, char_array);
}

```

And unfortunately, program crashed. 

As far as I understand, turns out that strlen can't figure out that if text == NULL, length should be 0...

Anyway, with this AddChar function, everything works:

```
void AddChar(char **text, char c) {
    if (*text == NULL) {
        *text = (char *) malloc(2);
        (*text)[0] = c;
        (*text)[1] = '\0';
    }
    else {
        *text= (char *) realloc(*text, sizeof(*text)+2);
        char char_array[2] = { c , '\0' };
        strcat(*text, char_array);
    }
}

```

.

.

I also had a problem with

```
void AddChar(char *text, char c) {
    text = "something";
}

```

not changing line->text, but changing \*text to \*\*text fixed that.