I am not clear about many things here.
Suppose the file to be transferred has 54 bytes.
(i) At the server side, while reading the file
in the first iteration :
I am reading 50 characters
in fread, so there is no place left for inserting '\0' in buf.
So, how does it matter, whether bzero has been used or not?
And the client is actually receiving those 50 bytes correctly.
(ii) In the next iteration, I read 4 bytes in buf.
What happens to the rest 46 bytes in buf[50]?
Does fread change them? Or do they have
previous values assigned to them? If they have
the previous values assigned to them, then
those characters should go to the client. Instead,
some strange binary data is being transmitted.
If fread changes them, then what does it
actually do with them?
Main Topics
Browse All Topics





by: sweetfa2Posted on 2008-10-12 at 12:13:56ID: 22698507
You are using fprintf to output your buffer. It expects a null terminated string for it to determine where the end of the buffer is. bzero fills your buffer with null characters so that only characters in the buffer are the ones that you have sent and the remainder of null characters, which is why fprintf currently works for you with bzero there.
read returns a length of the buffer read. common practice is to null terminate the buffer after the read if you intend to use printf functions, or you can restrict the length of your fprintf outpu tto the specified buffer length.