Hi All,
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.
raghavendra83
0
Newbie Poster
Recommended Answers
Jump to PostLook up fread and fwrite.
Jump to PostOff 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)
andfscanf(fp, "%d", &i)
you …
All 6 Replies
Narue
5,707
Bad Cop
Team Colleague
raghavendra83
0
Newbie Poster
raghavendra83
0
Newbie Poster
Murtan
317
Practically a Master Poster
raghavendra83
0
Newbie Poster
Murtan
317
Practically a Master Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.