I want to write a generic function which takes in a void pointer and length as input and writes the data referenced by the pointer to a file.
Another generic function which takes in a void pointer, length and offset and reads back the data to the memory referenced by the void pointer from the file.
Is it possible in C?
As fprintf needs the datatype to be specified, how can I achieve doing this? Is there any work around?
Thanks a lot for your time.
Jump to Post
Off the top of my head, I suspect that the fscanf is reading too many or not enough bytes.
I recommend that you either treat the whole file as binary or treat the whole file as ASCII.
Where you do
fprintf(fp, "%d\n", i)and
fscanf(fp, "%d", &i)you …
All 6 Replies
We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.