strcat gives error when I try to add a char to a char array
A char is a single character. A char * and a char[] are both arrays of characters (more correctly char * is a pointer to an array of characters).

strcat expects two arrays or pointers to arrays of characters. If you want to add a single character you can either fool the compiler into thinking that the character is an array of characters of size 1 (but it lacks the required NULL termination) or manually manipulate the target array.

For the former you could use strncat and casting:

strcat(some_char_array, &amp;c, 1);


That gives you a pointer to the character, which is as far as the compiler is concerned, indistinguishable to a pointer to an array of characters. You use the "n" variant of strcat  to limit it  to just one character (plus an added NULL character) so it doesn't rely on the missing NULL termination.

For the second you could do:

int n = strlen(some_char_array);
some_char_array[n] = c;
some_char_array[n+1] = 0;


That just sets the Nth character in the target array to whatever is in c, then adds a new NULL termination character to the end.