Thread: need help, but beware, i am in the twilight zone...

  1. #1
    Registered User
    Join Date
    Nov 2009

    need help, but beware, i am in the twilight zone...

    so im writing this program, that is similar to the linux/unix sort program...

    everything was going fine, in my testing phase... giving it random inputs, from a file...

    a.out < test

    and boom,

    (i enter control C here because it hangs)

    oddly enough, this only happens for certain inputs.
    trying to debug my program, still hours later, im at the point where i have it printf("START") after my opening brace.

    the file "test" contains lines of random #'s and letters, and my program sorts them.

    as i understand the way executables work, since my program works most of the time, and compiles, when i run it shouldnt it print "START" regardless what is in the test file?

    i mean, i give input 4 6 5, and it prints START 4 5 6, but then i give 4 0 6, and it prints nothing!! not even START. and printf is the very first statement. my program has not even begun to check the standard input and yet it hangs.

    THEN, i make a minor modification, instead of printf("START"); i put printf("START\n"), and it prints START with a new line!! yet it still seems to hang, but regardless i dont understand... why does it print START only when its followed by a newline??

    I realize i may be asked to show the offending code, but just in general, why would this occur? when i type a.out < test, is my program processing the test file before it actually runs the program??

    i really hope someone can give me some insight on what is going on...


  2. #2
    Registered User cph's Avatar
    Join Date
    Sep 2008
    could you please show us the source code.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Output like printf() is either buffered or unbuffered, depending on the system it's on. Your system is obviously buffered rather heavily.

    If you want to see it print something right away, use fflush(NameOfTheFilePointer);, or just get in the habit of including a newline at the end of all your printing lines of code. In the case of the screen, that also is a file stream, so flush(stdout).

    What sorting algorithm are you using in your program? Some, especially Quicksort, is very "brittle", and need to be coded up *JUST* right.
    Last edited by Adak; 11-16-2009 at 03:12 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. IPv6 zone index format
    By Mario F. in forum Tech Board
    Replies: 0
    Last Post: 10-05-2009, 11:28 AM
  2. Time Zone
    By fragrax in forum C Programming
    Replies: 3
    Last Post: 07-10-2008, 07:53 AM
  3. need some zone prog help
    By joeyzt in forum Windows Programming
    Replies: 0
    Last Post: 08-18-2003, 10:05 AM
  4. Image persistence (cue Twilight Zone theme...)
    By SMurf in forum Windows Programming
    Replies: 3
    Last Post: 04-21-2002, 10:24 PM