If you want to have a variable length, you need to use realloc(): http://www.cplusplus.com/reference/cstdlib/realloc/

The function doesn't allocate new memory, it's just "extended" the old memory (so you don't need to copy the old data to a new malloc()-block etc.)

I guess you don't want that also, but there is no other way besides using some external libraries like GLib