[Dev-C++] write and fwrite functions
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Dmitry S. <si...@si...> - 2005-04-11 08:33:39
|
Hello, dev-cpp-users.
I try to save binary data recieved from TCP socket into the file
...
#define DATA_BUFSIZE 4096
long totalRcvd = 0;
long nFileSize = 0;
int bytesRecv = SOCKET_ERROR;
char recvbuf[DATA_BUFSIZE];
int fd = open( "filename", O_CREAT|O_WRONLY );
while( bytesRecv == SOCKET_ERROR || bytesRecv > 0 ) {
bytesRecv = recv( sock, recvbuf, DATA_BUFSIZE, 0 );
totalRcvd += bytesRecv;
nFileSize += write( fd, recvbuf, bytesRecv );
}
close( fd );
totalRcvd and nFileSize are equal
nFileSize value is valid (I sent the same quantity of bytes to socket)
But real file size is bigger as nFileSize
And it is broken :(
When I use fopen, fwrite and fclose functions the result is rhe same
Why?
--
Dmitry
|