How will you print any character, string or value of a variable without library functions in C?

Manoj Doubts picture Manoj Doubts · Jan 22, 2009 · Viewed 8.6k times · Source

If for example I should not use standard library functions like printf(), putchar() then how can I print a character to the screen?

Is there an easy way of doing it. I dont know much about system calls and if I have to use them then how do I use them? So can any one advice an easy way of printing without using library functions?

Answer

derobert picture derobert · Jan 22, 2009

In standard C, you can't. The only I/O defined in C is through the C standard library functions.

On a given platform, there may be ways to do it:

  • Make kernel calls directly. You will probably need to write some inline assembly to do this. You could make litb's write call directly, without using your C library. Grab the source of your C library to see how it's done.
  • Write directly to the frame buffer. Multi-user OS's often disallow this (at least without making any library/kernel calls).

Unless you're writing your own C library, I'm not sure why you'd want to do this.