You can't, you're going to have to use a more expressive representation that can hold such meta information.
Memory is memory, there's no way to determine if it has been "used" or not, since it's there all the time once you've allocated it.
If you can't use the sentinel approach (like C strings, have a terminator indicate end-of-valid-data) you're going to have to use explicit length values or some other approach that expresses this.
Also, please don't cast the return value of malloc()
in C.
Further, don't scale allocations by sizeof (char)
since that's always 1 you're only adding noise. This is, quite obviosuly, my opinion. Your code will never be technically wrong if it includes that multiplication, and some clearly feel that it adds value and makes the code clearer.
Finally, you are doing 100 heap-allocations of 3 bytes each, that is very inefficient. I would suggest just doing an array of 100 3-byte arrays (possibly expressed as an array of struct
s).