jonjohnson
jonjohnson

Reputation: 423

Printing out to console with sleep in Linux

I'm trying to do a matrix style program where letters fall from the top to bottom in console in Linux using C. Each line should be written with a lapse of 0.1 of a second. For now I am just printing out random letters in dependency of width and height of the console. But the problem is the output is quite different. It doesn't print out line by line. It prints about a half of the screen and then the second half. So if the height of the screen would be 20 units, it would take 1 second to write ten lines, and then after another second it would display the remainig 10 lines in 1 single shot. For sleep im using nanosleep() and I have tried printf(), fprintf, putc() all ending with the same result.

Upvotes: 1

Views: 208

Answers (1)

Fred Larson
Fred Larson

Reputation: 62073

It sounds like buffering. Try putting a fflush() call after your fprintf().

Upvotes: 3

Related Questions