S
SW1
I wrote a small program which does something like tftp - transfering
files and some chat, anyway i got a problem with fwrite, here is a
snippet of my code:
while(length > 0) {
putchar('.'); //These were for error checking
if(length <= bsize) { //Buffer is bigger than remaining File
realloc(buffer,length * sizeof(char)); //resize buffer
to remain
rec = recv(sock,buffer,length,0); //recieve Data
p = buffer; //set p to buffer
i = length; //set i to remain
while(i > 128) { //break down into 128byte blocks
putchar('.');
fwrite(p,sizeof(char),128,writefile);
p = p + 128; //go to next 128 bytes
i = i - 128;
}
fwrite(p,sizeof(char),i,writefile);
} else {
rec = recv(sock,buffer,bsize,0); //bsize is 1024
putchar('.');
p = buffer;
for(i=0;i<8;i++) {
fwrite(p,sizeof(char),128,writefile);
putchar('.');
p = p + 128;
}
}
length is the length of the whole file to be transmitted, bsize is the
size of the recieve buffer, sock is a socket, p is as pointer, rec and
i are integers.
And now comes my Problem i compiled this code and ran it under Windows
2000 (being the reciever) and it hangs at the fwrite calls (since I
see 2 dots) then i copied the programm to my WinXP machine and it ran
happily!!!
Has Anybody got any Idea whats wrong there??? I costed me 6 hours till
i figured out that it wasn't my fault (after that i tried it on winXP)
One thing to add is whats up with that strange breaking down into 128
Blocks. I ran a small test programm ever increasing the number of
bytes written at once with fwrite, and i got an Error around 140 so i
thought 128 bytes at once should be save.
Thank you soo much.
files and some chat, anyway i got a problem with fwrite, here is a
snippet of my code:
while(length > 0) {
putchar('.'); //These were for error checking
if(length <= bsize) { //Buffer is bigger than remaining File
realloc(buffer,length * sizeof(char)); //resize buffer
to remain
rec = recv(sock,buffer,length,0); //recieve Data
p = buffer; //set p to buffer
i = length; //set i to remain
while(i > 128) { //break down into 128byte blocks
putchar('.');
fwrite(p,sizeof(char),128,writefile);
p = p + 128; //go to next 128 bytes
i = i - 128;
}
fwrite(p,sizeof(char),i,writefile);
} else {
rec = recv(sock,buffer,bsize,0); //bsize is 1024
putchar('.');
p = buffer;
for(i=0;i<8;i++) {
fwrite(p,sizeof(char),128,writefile);
putchar('.');
p = p + 128;
}
}
length is the length of the whole file to be transmitted, bsize is the
size of the recieve buffer, sock is a socket, p is as pointer, rec and
i are integers.
And now comes my Problem i compiled this code and ran it under Windows
2000 (being the reciever) and it hangs at the fwrite calls (since I
see 2 dots) then i copied the programm to my WinXP machine and it ran
happily!!!
Has Anybody got any Idea whats wrong there??? I costed me 6 hours till
i figured out that it wasn't my fault (after that i tried it on winXP)
One thing to add is whats up with that strange breaking down into 128
Blocks. I ran a small test programm ever increasing the number of
bytes written at once with fwrite, and i got an Error around 140 so i
thought 128 bytes at once should be save.
Thank you soo much.