I have the following snippet where I read sent bytes usingread() and store the data in a buffer which works well. But how do i make it so that I can continue to write in binary file after every read. My assumption is that it might have something to do with not resetting the buffer. Thanks for the help!
fp = fopen (filename, "wb"); //create a file
while (size > 0){
n = read(socket,buffer,size*sizeof(char));
if (n <=0)
return -1;
p += n;
size -= n;
fwrite(buffer,sizeof(char),size*sizeof(char),fp); //write the content to the file
}
fpiffopen()was successful.