Keil c51:printf sprintf vprintf vsprintf function Learning

Source: Internet
Author: User
Tags sprintf

In the Keil installation directory, where there are STDIO.H several print functions are as follows:

extern int printf   (const char *, ...);
extern int sprintf  (char *, const char *, ...);
extern int vprintf  (const char *, char *);
extern int vsprintf (char *, const char *, char *);

vprintf corresponds to printf, which prints the data in ASCII format to the serial port

The vsprintf corresponds to sprintf, which prints the data in ASCII format to buffer.


The sprintf function formats a series of strings and numeric values and stores the resulting string in buffer.

This function was similar to the printf routine, but it stores the formatted output in buffer rather than sending it to the Output stream.

The principle of printf is to start from the serial port from the "character pointer variable" (single-byte pointer), and if it encounters a '/' (0x00) stop sending, note that this 0x00 is not sent.


buffer[0]=0x00;
buffer[2]=0x00;	buffer[2]=0x01; 
TI = 1;
ES = 0;
printf (buffer);
ES = 1;	


This will not send any data, because the first byte of buffer points to the data is 0x00, then the data will not be sent.

However, if BUFFER[0] is a non-0x00 data, it can be sent, but Buffer[1] is not initialized by default, so only the first data is sent.

So if you want to send an array that includes 0x00, then you can't use the printf function. You want to use a for loop to send data through the entire array.



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.