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?
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:
write
call directly, without using your C library. Grab the source of your C library to see how it's done.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With