![]() |
writing to the screen using unbuffered io
Anyone know how to write to the screen using unbuffered IO? Is this even possible? I know about the sprintf() function and have used that to fill a buffer with the message i want displayed but I am unsure of how to display it to the screen.
|
I'm sorry if I'm misunderstanding the question, but are you looking for the "printf" function?
|
yea but isn't printf buffered. I basically need the unbuffered IO inequivalent to printf. That is if one exists.
|
The standard way is to call fflush(stdout) after each call of printf(). If stdout is buffered then that will flush any buffers.
|
i cant use printf what about calling fflush after an sprintf would that flush the string that got filled up in sprintf to the screen?
|
sprintf is a printf that writes to a string, not to the output. If you can use it, why can't you use printf? Perhaps you could explain in more detail what you want to do and why you have restrictions against normal usage (and what the restrictions are).
|
well the one restriction is i can not use buffered io. Isn't printf considered being buffered IO? This is what I'm not sure about. Or is printf the only way to write to stdout which would be the screen?
|
You could use low-level I/O to output the material preformatted by sprintf. Another quick way would be to use stderr (via fprintf), which is unbuffered, rather than stdio.
|
i figured it out. sprintf is used to fill the string and then write is used to write the string and then you pass either STDOUT_FILENO for the screen cause its standard out or STDERR_FILENO for standard error
|
Quote:
In general, there is no specific requirement that printf() be buffered. That is an implementation detail of your compiler/library. If it is buffered, fflush() will flush the buffer. Buffered I/O is generally only stated as a requirement for learning purposes or as a result of poor design. Using unbuffered I/O is generally a solution that meets a requirement, not a requirement in its own right. |
| All times are GMT -5. The time now is 2:20 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC