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

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.


In linux, you can use the write system-call:

write(1, "hello\n", 6); // write hello\n to stdout

If you can't get enough of it, you can go one step lower, invoking the syscall generically:

syscall(__NR_write, 1, "hello\n", 6);

It's worth knowing about strace, which you can use to see which syscalls are used by any particular program while it runs. But note that for "some simple parser", it's hardly needed to use raw system calls. Better use the functions of the c library.

By the way, lookout for WriteFile and GetStdHandle functions if you want to do the above in Windows without using the c standard library. Won't be as l33t as the linux solution though.


Well thank u all for ur answers.I found one simple answer by a comment from Mr. Hao below the question. his answer is simple program like this

Turbo C(DOS program):

char far* src = (char far*) 0xB8000000L; 
*src = 'M'; 
src += 2; 
*src = 'D'; 

or try this: http://en.wikipedia.org/wiki/Brainfuck :) – //Hao (an hour ago)

I tried it on Turbo C and its working. I wanted a simple solution like this and I wanted to accept it as correct answer but he(Hao) gave it as a comment so I pasted it here for other users to know about this on behalf of him and accepted it. Once again thank u Mr.Hao.