Originally Posted by
Quantum1024
Don't use string functions like fputs with what you get from a recv call. There is no guantee that it willl be null terminated (as pointed out in
this thread) and this may well be the source of your problem when recieving a binary file.
Use fwrite, and use the number of bytes returned by recv() as the amount of bytes to write to the file. Loop untill you get a 0 or -1(error).
Now I have it that way:
It works but only until j reaches the size of buf, here 4096, how can I make the buf char as big as the file I recive?
Code:
unsigned int j = 0;
do {
if (recv(h,&buf[j],1,0)==SOCKET_ERROR) {
addlog("retlinehttp(): recv() Failed! %d", WSAGetLastError());
return -2;
}
fwrite (&buf[j] , 1 , 1 , file);
j++;
} while (j < sizeof(buf));