Hi DIC, I just have a quick question, and I might follow it up with a more involved problem with code later.
Note: I'm referring to character arrays as strings here, for simplicity.
I want to make a dynamic array of structs, but currently when I use realloc (and especially when realloc moves the code block), the data inside my structs (fixed length strings that only get modified with strcpy, to add to the confusion)gets pretty mangled, looking very similar to strings that have overwritten their null terminator.
Can this be avoided if I make the dynamic array point to strings instead?
Can I malloc the strings inside the structs, as well as the array? This sounds like a nightmare, but would be incredibly helpful.
Alternatively, what is the best way to make a dynamic array of structs, specifically those including strings?
Note: I'm referring to character arrays as strings here, for simplicity.
I want to make a dynamic array of structs, but currently when I use realloc (and especially when realloc moves the code block), the data inside my structs (fixed length strings that only get modified with strcpy, to add to the confusion)gets pretty mangled, looking very similar to strings that have overwritten their null terminator.
Can this be avoided if I make the dynamic array point to strings instead?
Can I malloc the strings inside the structs, as well as the array? This sounds like a nightmare, but would be incredibly helpful.
Alternatively, what is the best way to make a dynamic array of structs, specifically those including strings?