putchar(char) writes a character to standard output and is normally provided by stdio.h.
How do I write a character to standard output without using stdio.h or any other standard library file (that is: no #include:s allowed)?
Or phrased different, how do I implement my own putchar(char) with zero #include statements?
This is what I want to achieve:
/* NOTE: No #include:s allowed! :-) */
void putchar(char c) {
/*
* Correct answer to this question == Code that implements putchar(char).
* Please note: no #include:s allowed. Not even a single one :-)
*/
}
int main() {
putchar('H');
putchar('i');
putchar('!');
putchar('\n');
return 0;
}
Clarifications:
- Please note: No
#include:s allowed. Not even a single one 🙂 - The solution does not have to be portable (inline assembler is hence OK), but it must compile with gcc under MacOS X.
Definition of correct answer:
- A working
putchar(char c)function. Nothing more, nothing less 🙂
1 Answer