Diverse sprintf Functions

Source: Internet
Author: User

Function types:

There are many string output functions, as shown in the following table:

 

 

 

ASCII

Wide text

General

 Number of parameters

 

 

 

Standard Edition

Sprintf

Swprintf

_ Stprintf

Max length Edition

_ Snprintf

_ Snwprintf

_ Sntprintf

Windows

WsprintfA

WsprintfW

Wsprintf

 Parameter array metrics

 

 

 

Standard Edition

Vsprintf

Vswprintf

_ Vstprintf

Max length Edition

_ Vsnprintf

_ Vsnwprintf

_ Vsntprintf

Windows

WvsprintfA

WvsprintfW

Wvsprintf

 

Function usage:

 

The functions listed in the preceding table are the most important and commonly used:

1. the maximum length of the number of parameters:

Prototype: int _ snprintf (char * _ Dest, size_t _ Count, const char * _ Format ,...)

_ Count indicates the maximum number of characters that can be stored in the target address space.

Example:

1. char szBuffer [100];

2. _ snprintf (szBuffer, sizeof (szBuffer), "The sum of % I and % I is % I", 5, 3, 5 + 3 );

 

2. Maximum length of the indicator of the parameter array:

Prototype: int _ vsnprintf (char * _ Dest, size_t _ Count, const char * _ Format, va_list _ Args)

_ Count indicates the maximum number of characters that can be stored in the target address space,

Va_list is the type defined by the C standard library.

Example: in fact, one possible internal implementation method of the _ snprintf function is to use the _ vsnprintf function for implementation:

1. int _ snprintf (char * szBuffer, size_t count, const char * szFormat ,...)

2 .{

3. int iReturn;

4. va_list pArgs;

5. va_start (pArgs, szFormat );

6. iReturn = _ vsnprintf (szBuffer, count, szFormat, pArgs );

7. va_end (pArgs );

8. return iReturn;

}

From: blog

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.