Output % d, % c, % p, % s in the basic format of printf in c Language

Source: Internet
Author: User

Output % d, % c, % p, % s in the basic format of printf in c Language

As for the implementation of printf, I must have read many basic knowledge from my previous articles. Well, let's not talk about it anymore. Go to the source code and look at a simple implementation method:

 

# Include

 
  
# Define myfflush (out) do {} while (0) typedef int uint32_t; // output decimal number static void print_Dec (uint32_t n) {if (n> = 10) {// call print_Dec recursively (n/10); n % = 10;} putchar (char) (n + '0 '));} // output hexadecimal number static void print_Hex (unsigned int hex) {int I = 8; putchar ('0'); putchar ('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 hexadecimal number print_Dec (10); putchar ('\ n '); // output hexadecimal number print_Hex (0xa); putchar ('\ n'); // output string print_String ("hello world"); myfflush (stdout ); return 0 ;}

 
Running result:

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.