I have tried to dynamically set the size of an array depending on a input fileīs size.
What I have done is, first using fseek() and ftell() to fetch the start and end of the data in the file.
I then subrtact start from end and store that in the variable size.
What I would like to know now is if using size in an array declaration actually works as I expect it to or if I have to use malloc().
This is what I tried first:
I wasnīt actually sure if this would work under all conditions, so I tried malloc like this:Code:UInt8 dataArray[size]; // where size is the previously unknown size of the file or data
Iīm trying to use the void pointer to access different places in dataArray by increment itīs value here.Code:UInt8 *dataArray = malloc(size); void *dataPt = NULL; dataPt = &dataArray;
This gives me this warning: assignment makes integer from pointer without a castCode:for(dataCounter = 0; dataCounter < 120; dataCounter++) { data[i].data[dataCounter] = *dataPt; dataPt++; }
If I try to cast it Iīm informed that I should not attempt to cast a void pointer? I thought that was what they where good for.
EDIT: This was weird, I just tried to compile this again and got a new error and warning like this:
warning: dereferencing ‘void *’ pointer
error: void value not ignored as it ought to be