-2
I have a dynamically allocated two-dimensional char matrix, as I do to get its size?
would use sizeof(client);
for example, I instated a client struct, Client **client; then in the code I’ll allocate it as it goes (tamVetor ++ and realloc); receiving data in its structure:
int tamVetor = 0; example: client = realloc(sizeof(char*)tamVetor); client[i] = malloc(sizeof(char)*150);
Within the function this code is implemented I can print the x indices of the struct wherever, for(int i = 0; i < tamVetor; i++);
However, this function returns the struct to another function that called it, example:
char **result = (function that receives return to struct);
In that function now I want to print the fields of the structs, but doing sizeof(result); always gives a very low value that I do not know giving came .
And for example, if I know that I have 12 clients of my struct, and in this function, when printing the fields of the struct on the screen I place(int i = 0; i < 12; i++) printa correctly, but if I place it is(int i = 0; i < sizeof(result); i++); print only a few clients, but no error at all.
sizeof()
is calculated in compilation time. It does not help at all to calculate the size of a memory block allocated in running time.– Lacobus