-
format help "%10000c"
I am working on a http server, and I am having problem with uploading images. When i am looping the stream for the image file date, I can only get some of the image before the fscanf function stalls. The way I have done the format works fine with text files but not with image files. Any idea what is wrong?
fscanf ( file, "%10000c", buffer )
-
%c is for a single character. What exactly are you doing?
Quzah.
-
Trying to read 10KB/s from a socket.
-
If that is how you are doing it I would seriously check out Beejs Socket guide on the web. You will probably have your eyes opened alot...
First lesson: you cannot EVER count on getting any specific number of bytes in a single packet. You need to loop and accumulate bytes until you get however many you are expecting. TCP guarantees that the bytes WILL get there and get there in order but not how fast or when..
-
This is my attempt at it.
Code:
else if ( strcmp ( request, "POST" ) == 0 ) {
strcpy ( buffer, "" );
int goal = 4593; // file size
char *format = malloc ( 10 );
char *dfg = malloc ( 1024 );
int okay = 0;
int KB = (20)*1024;
while ( okay < goal ) {
strcat ( format, "%" );
sprintf ( dfg, "%d", ( ( okay+KB ) < goal )? KB: goal-okay );
strcat ( format, dfg );
strcat ( format, "c" );
fscanf ( f, format, bufer );
strcat ( buffer, bufer );
strcpy ( format, "" );
okay = strlen ( buffer );
sleep ( 1 );
}
}
-
Uhm I looked all of that over and do not see anywhere where you are looping on the socket getting bytes....I do wonder what the point of strcpy(buffer, "") is..
-
The while is made to keep reading the socket until the Byte goal has been reached because I had a problem when I tried to just add the number of bytes that fscanf tried to return.
I used buffer earlier in the code to hold some header information, and I didn't want to free up the memory yet.
-