format help "%10000c"

This is a discussion on format help "%10000c" within the C Programming forums, part of the General Programming Boards category; I am working on a http server, and I am having problem with uploading images. When i am looping the ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    5

    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 )

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    %c is for a single character. What exactly are you doing?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    5
    Trying to read 10KB/s from a socket.

  4. #4
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    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..
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    5
    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 );
    			}
    		}

  6. #6
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    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..
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    5
    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.

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    5
    Thanks, you guys. btw.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Zoom
    By jma619 in forum C Programming
    Replies: 1
    Last Post: 09-13-2009, 05:13 AM
  2. GradeInfo
    By kirksson in forum C Programming
    Replies: 23
    Last Post: 07-16-2008, 03:27 PM
  3. function returning hour in either 12 or 24 hour format
    By stanlvw in forum C Programming
    Replies: 4
    Last Post: 01-01-2008, 05:02 AM
  4. Compression/Decompression Wave File and MP3
    By cindy_16051988 in forum Projects and Job Recruitment
    Replies: 51
    Last Post: 04-29-2006, 06:25 AM
  5. Seeking Format Advice
    By PsychoBrat in forum Game Programming
    Replies: 3
    Last Post: 10-05-2005, 05:41 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21