C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-16-2009, 12:31 AM   #1
Registered User
 
Join Date: Nov 2009
Posts: 3
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!
theonlywalks is offline   Reply With Quote
Old 11-16-2009, 12:51 AM   #2
cph
Registered User
 
cph's Avatar
 
Join Date: Sep 2008
Location: Indonesia
Posts: 32
could you please show us the source code.
cph is offline   Reply With Quote
Old 11-16-2009, 01:03 AM   #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   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 12:45 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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