I want to reallocate an array of structs in C (add one struct at the end) but it doesn't change its size:
typedef struct stone {
int height;
int width;
int length;
int color;
} STONE;
int main() {
STONE *stone;
stone = (STONE *)calloc(1, sizeof(STONE));
int length = 0;
int command = 1;
while (command != 0) {
printf("Choose the method: \n");
printf("[0] - add stone\n");
printf("[1] - show stone\n");
printf("[2] - remove stone\n");
printf("[3] - compare stone\n");
printf("[4] - exit program\n");
printf("Input: ");
scanf("%d", &command);
switch (command) {
case 0:
length++;
stone= (STONE *)realloc(stone, sizeof(STONE) * length);
STONE *d = stone+ (sizeof(STONE) * (length - 1));
break;
case 1:
ausgabeBS(*(stone + length * sizeof(STONE) - sizeof(STONE)));
break;
case 2:
break;
case 3:
break;
default:
return 0;
}
}
return 0;
}
Why is this? I output the size of the array and it always stays at 4 Bytes.
//code I used to output the size
printf("%d", sizeof(stone));
I hope you can help me - thanks!