Resizing an array with C
问题 I need to have an array of structs in a game I'm making - but I don't want to limit the array to a fixed size. I'm told there is a way to use realloc to make the array bigger when it needs to, but can't find any working examples of this. Could someone please show me how to do this? 回答1: Start off by creating the array: structName ** sarray = (structName **) malloc(0 * sizeof(structName *)); Always keep track of the size separately: size_t sarray_len = 0; To increase or truncate: sarray =