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