LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-08-2008, 06:23 PM   #1
violagirl23
Member
 
Registered: Aug 2007
Location: Michigan
Distribution: Gentoo, Arch
Posts: 33

Rep: Reputation: 15
Ncurses: printw(); prints to screen even if refresh(); is not called - why?


All the tutorials I have read say that the changes you make in output will not actually display unless you call refresh();. I liked that idea because I could make several changes before displaying them. However, it doesn't seem to make a difference whether I use it or not-- printw() prints to the screen. How can I change this?
(The language is C++).
 
Old 03-09-2008, 02:14 PM   #2
zensunni
Member
 
Registered: Feb 2008
Posts: 45

Rep: Reputation: 0
I had this exact same question when I was using ncurses. I basically shrugged it off and didn't worry about refreshing, but I'm still curious why this is the case. Anyone?
 
Old 03-10-2008, 07:37 AM   #3
orgcandman
Member
 
Registered: May 2002
Location: new hampshire
Distribution: Fedora, RHEL
Posts: 600

Rep: Reputation: 110Reputation: 110
Not an ncurses guy myself, however my guess after reading some google would be that printw() behaves in a similar fashion to printf(). Namely, if you use '\n' at the end of the text, it will auto flush the stream to which you're writing. My guess (again from reading code) is that refresh() is a flush() analog.

I could be wrong. Experiment :P
 
Old 03-10-2008, 08:12 AM   #4
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Hi

I don't know ncurses either. But it could be it's because standard output is line buffered. Maybe add this somewhere in the beginning to make it fully buffered:

setvbuf(stdout,NULL,_IOFBF,8192);

This changes stdout so the output is buffered, and sets the buffer size to 8k. Then no output will be visible until the buffer is full or fflush(stdout) is called. The refresh() probably does an fflush on stdout.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
kern.log prints to screen on error mandrakethepenguin Linux - General 1 08-04-2006 01:15 PM
CUPS Printer Problem - prints, but prints gibberish Sparrowhawk Debian 2 06-19-2006 07:32 PM
cups prints poorly, while lpr from command line prints well spindles Linux - Software 2 04-01-2006 04:02 AM
what is the role of refresh function in ncurses? saied Programming 1 08-04-2005 02:16 PM
ncurses - init screen after systemcall lea Programming 3 10-24-2002 11:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration