char *string_t is a pointer, not an uninitialized char array. Its size is fixed to whatever is the size of a pointer on your system, which appears to be eight.
sizeof(*string_t) is the same as sizeof(char), so it is fixed at 1 by the C standard. There is no way to produce the behavior that you expect without changing from pointers to arrays.
If you would like to make an array that you resize by realloc-ing, you need to make a struct that keeps track of both the pointer and the size (or has two pointers pointing to the beginning and to the end of the allocated block).
struct dynamic_char_array {
char *array;
size_t size;
};
void add_char(struct dynamic_char_array* a, char c) {
char *tmp = realloc(a->array, (a->size)+1);
if (tmp) {
a->array = tmp;
} else {
// Do something about a failed allocation
...
return;
}
a->array[size++] = c;
}
Note: You could also use variable-length arrays, but once their size is set, it cannot be changed.
0exactly?sizeof(string_t)/sizeof(*string_t)is how you find the length of a char array[ ].