When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
1 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
what isn't working about your implementation for 4?
what do you mean by 'removing bytes'?
'removing bytes' from an array doesn't really make sense in the C world
an array is a chunk of bytes with a fixed size
but what do you mean by 'remove anything', as in make all of the bytes 0?
That isn't possible, an array has a fixed size once it's created
Maybe I should try a different approach.
Not really, because you don't know the sizes at compile time you're creating VLAs
Which are somewhat of a sin in C
I would recommend using dynamic memory allocation (e.g. malloc)
+ 1. Creates x random bytes and assign it to a variable {somehow}...
+ 2. Save the contents (of the variable) to a .bin file.
+ 3. Read the contents of a .bin file and store it to a variable {somehow}...
+ 4. Copy the last x bytes of the {somehow created} variable and assign it to another variable. Delete the copied bytes from the {somehow created} variable...
@late fossil how would you do this?
*random bytes
I see. I used arrays because I recently learned about them, however malloc is new to me.
I can already sense the memory leaks.
What are VLAs?
@late fossil
Ah, I think I can also just move the file pointer:
fseek(file, -number_of_bytes_to_read, SEEK_END);
VLAs are variable length arrays
arrays get allocated on the stack, and usually the compiler knows the size of everything on the stack at compile time
but it doesn't know that about VLAs, which means that they're really slow to use
Ah good to know 🙂 Thanks
@dense jackal Has your question been resolved? If so, run !solved :)
@dense jackal
Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.
!solved