0

I am trying to implement a distributed file system and for that I have to read files in chunks (files can be of any type image, audio, video, text, etc).

`typedef struct chunk_structure{
int chunk_id;

int is_last;

char file_name[100];

char buffer[2048];

//some other fields
}`

I am reading 2048 bytes from the file using fread copy it to a struct chunk_structure variable and pass it on to the data server. Data server stores each chunk to a different binary file using fwrite but while retrieving the value, though, I get some of the file contents, I also get some random characters.

Can someone please explain what could have gone wrong? or if can anyone suggest a different way of doing this.

Sunil Kumar Jha
  • 841
  • 1
  • 8
  • 11
  • If someone downvotes the question, please state the reason as well so that I can improve next time. – Sunil Kumar Jha Sep 28 '20 at 06:10
  • Can you show how you're using this in a [mcve]? What platform are you on? Are you opening the files in binary mode? – Retired Ninja Sep 28 '20 at 06:20
  • Since i dont have much code, I can only speculate, and never answer. Are you sure you are null-terminating the buffer though ? – A P Jo Sep 28 '20 at 11:10

0 Answers0