C-program is not able to print '\n' after system("clear") command
I have the following program:
Code:
main() hello Problem: It is not printing new line, the programs somehow ignores it and directly prints "hello" on the first line of the terminal. But when I was not using system command then '\n' works fine. |
Hya
Two points to clarify. 1. #include ...... 2. System buffer cheers |
Hi and welcome to LQ.
In the future, and note that you can edit your original post, you should use [code][/code] tags around your code. This will retain the spacing and formatting and make it easier to read. You probably should explain, if this is the case, that you're just learning and experimenting. It's not a really purposeful program, and I'm the type of person who "grew up" being told to never use the system() call. :) Nothing bad, just more helpful for people to be able to help you. So, a suggested solution: How about trying: Code:
printf("\nhello"); |
First, you should #include the required header files, to declare the functions that you use in your program (i.e., printf, system, and sleep):
Code:
#include <stdlib.h> Code:
void main(void) Code:
setbuf(stdout, NULL); Code:
fflush(stdout); |
Quote:
Code:
printf("\033\143\nhello\n"); |
Thank you Guys for replying..
kaz and luvr was right, it was about stdout buffer, i used setbuf(stdout,NULL) and problem is now solved, and i used all that three header files it was not the issue. thanks keefaz for "clear" alternative, and rtmistler thank you 4 ur help, thanks guys. |
Most likely, the problem was the lack of fflush(stdout)
|
I did not used fflush but still code works fine, so why you are saying lack?
|
You should add fflush after printf:
Code:
... |
Quote:
|
okeh got it thanks.
|
All times are GMT -5. The time now is 02:56 PM. |