As for the realization of printf, I must have seen a lot of basic knowledge from the partners who have read the articles I have published before. OK, then not much to say, directly on the source code, to see a simple way to achieve:
#include <stdio.h> #define Myfflush (out) does {} while (0) typedef INT uint32_t;//output decimal number static void Print_dec (uint32_t n) { if (n >=) { //recursive call Print_dec (N/10); n%=; } Putchar ((char) (n + ' 0 '));} Output hexadecimal number static void Print_hex (unsigned int Hex) {int i = 8;putchar (' 0 ');p utchar (' x '), while (i--) {unsigned char c = (Hex & 0xf0000000) >> 28;putchar (c < 0xa? C + ' 0 ': c-0xa + ' a '); hex <<= 4;}} Output string void print_string (const char *s) {while (*s) {Putchar (*s); s++;}} Output character void Print_char (char ch) {Putchar (ch);} typedef unsigned long volatile ULV; typedef unsigned long ul; int main (void) {//output 10 binary print_dec ();p utchar (' \ n ');//Output 16 Binary Print_hex (0xa);p Utchar (' \ n ');//output string print_string ("Hello World"); Myfflush (stdout); return 0; }
Operation Result:
C language implements the basic format output of printf%d,%c,%p,%s