C language implements the basic format output of printf%d,%c,%p,%s

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.