![]() |
| | #1 |
| Registered User Join Date: Nov 2009
Posts: 3
| need help, but beware, i am in the twilight zone... 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! |
| theonlywalks is offline | |
| | #2 |
| Registered User Join Date: Sep 2008 Location: Indonesia
Posts: 32
| could you please show us the source code. |
| cph is offline | |
| | #3 |
| Registered User Join Date: Sep 2006
Posts: 3,148
| 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. |
| Adak is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| IPv6 zone index format | Mario F. | Tech Board | 0 | 10-05-2009 11:28 AM |
| Time Zone | fragrax | C Programming | 3 | 07-10-2008 07:53 AM |
| need some zone prog help | joeyzt | Windows Programming | 0 | 08-18-2003 10:05 AM |
| Image persistence (cue Twilight Zone theme...) | SMurf | Windows Programming | 3 | 04-21-2002 10:24 PM |