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

This is a discussion on need help, but beware, i am in the twilight zone... within the C Programming forums, part of the General Programming Boards category; so im writing this program, that is similar to the linux/unix sort program... everything was going fine, in my testing ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    7

    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...

    thanks!

  2. #2
    cph
    cph is offline
    Registered User cph's Avatar
    Join Date
    Sep 2008
    Location
    Indonesia
    Posts
    82
    could you please show us the source code.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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 02: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

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