Tuesday, July 14, 2009

Can we print a statement on out put screen without using any print statements in c-programing language?

if i want want to print "hello" or any other string generally we use printf statement in c-language.But i want to know ,can we print a string on out put console witout using printf statement

Can we print a statement on out put screen without using any print statements in c-programing language?
Printf() is what is typically used from the Standard C Library. However, if you need to make a non-standard call, there are usually operating system specific functions to accomplish native I/O. Printf() is portable but other calls won't be cross-platform.





If you're writing in terms of Unix, take a look at the Curses Library (see links below). Using curses, programmers are able to write text-based applications without writing directly for any specific terminal type. The curses library on the executing system sends the correct control characters based on the terminal type. It provides an abstraction of one or more windows that maps onto the terminal screen. Each window is represented by a character matrix. The programmer sets up each window to look as they want the display to look, and then tells the curses package to update the screen. The library determines a minimal set of changes needed to update the display and then executes these using the terminal's specific capabilities and control sequences.





For the DOS console, you'd most likely make BIOS calls (interrupt 10h) which printf() eventually ends up executing. If you have a Windows-based system, there is always DirectX or OpenGL...





For completeness, I should mention that on some machines, there is memory-mapped I/O for the video hardware. Therefore, you could determine the method to address the video hardware directly assuming the OS allows it (without writing your own device driver). You'd need to be much more specific with your question to determine if this is what you're seeking.





Note: tadds, you're supplying C++ code (Stream I/O) instead of the requested C-only advise.
Reply:Try this





#include %26lt;iostream%26gt;


using namespace std;





int main()


{


cout %26lt;%26lt; "hello";


}
Reply:The first guy is suggesting a different programming language and unfortunately has no idea what he's talking about and absolutely no right to be giving you information.





I'm not sure what you're asking in your question as it appears to ask two different things. First, you want to know if you can print to the screen without calling a print statement. This is, of course, not easily done as you would have to edit the process of the console to manipulate the text in the console. Attempting to access data outside of your program's scope will not be allowed by the operating system so some significant hack work would be involved.





Then you ask if you can print to the screen in C without printf()... sure, if you use another function. How about... fprintf()?





fprintf(stdout, "Hello");





You should be using fprintf() over printf() anyway. As the second poster said, there are other methods to write text to the screen.


No comments:

Post a Comment