wsprintf

Version 3.0

Syntax

int wsprintf(lpOutput,lpFormat[[,argument]]...)

This function formats and stores a series of characters and values in a buffer. Each argument (if any) is converted and output according to the corresponding format specification in the format string. The function appends a NULL to the end of the characters written, but the return value does not include the terminating null character in its character count.

Parameter Type/Description  

lpOutput LPSTR Points to a null-terminated character string to receive the formatted output.  
lpFormat LPSTR Points to a null-terminated character string that contains the format-control string. In addition to ordinary ASCII characters, a format specification for each argument appears in this string. See the following “Comments” section for more information on the format specification.  
argument Is one or more optional arguments. The number and type of argument parameters depends on the corresponding format-control character sequences in lpFormat.  

Return Value

The return value is the number of characters stored in lpOutput, not counting the terminating NULL. If an error occurs, the function returns a value less than the length of lpFormat.

Comments

The format-control string contains format specifications that determine the output format for the arguments which follow the lpFormat parameter. Format specifications, discussed below, always begin with a percent sign (%). If a percent sign is followed by a character that has no meaning, such as a format field, the character is output as is. For example, %% produces a single percent-sign character.

The format-control string is read from left to right. When the first format specification (if any) is encountered, it causes the value of the first argument after the format-control string to be converted and output according to the format specification. The second format specification causes the second argument to be converted and output, and so on. If there are more arguments than there are format specifications, the extra arguments are ignored. The results are undefined if there are not enough arguments for all of the format specifications.

A format specification has the following form:

%[[–]][[#]][[0]][[width]][[.precision]]type

Each field of the format specification is a single character or a number signifying a particular format option. The type characters, which appear after the last optional format field, determine whether the associated argument is interpreted as a character, a string, or a number. The simplest format specification contains only the percent sign and a type character (for example, %s). The optional fields control other aspects of the formatting. The following shows the optional and required fields and their meaning:

Field Description  

Pad the output with blanks or zeroes to the right to fill the field width, justifying the output to the left. If this field is omitted, the output is padded to the left, justifying the output to the right.  
# Prefix hexadecimal values with 0x (lowercase) or OX (uppercase).  
0 Pad the output value with zeroes to fill the field width. If this field is omitted, the output value is padded with blank spaces.  
width Output the specified minimum number of characters. The width field is a nonnegative integer. The width specification never causes a value to be truncated; if the number of characters in the output value is greater than the specified width, or if the width field is not present, all characters of the value are printed, subject to the precision specification.  
precision Output the specified minimum number of digits. If the number of digits in the argument is less than the specified precision, the output value is padded on the left with zeroes. The value is not truncated  
  when the number of digits exceeds the specified precision. If the specified precision is 0, omitted entirely, or if the period (.) appears without a number following it, the precision is set to 1.  
  For strings, output the specified maximum number of characters.  
type Output the corresponding argument as a character, string, or a number. This field may be any of the following character sequences:  
  Sequence Meaning
  s Insert a string argument referenced by a long pointer. The argument corresponding to this sequence must be passed as a long pointer (LPSTR).
  c Insert a single character argument. The wsprintf function ignores character arguments with a numerical value of zero.
  d, i Insert a signed decimal integer argument.
  ld, li Insert a long signed decimal integer argument.
  u Insert an unsigned integer argument.
  lu Insert a long unsigned integer argument.
  x, X Insert an unsigned hexadecimal integer argument in lowercase or uppercase.
  lx, lX Insert a long unsigned hexadecimal integer argument in lowercase or uppercase.

NOTE:

Unlike all other Windows functions, wsprintf uses the C calling convention (cdecl), rather than the Pascal calling convention. As a result, it is the caller's responsibility to pop arguments off the stack, and arguments are pushed in reverse order (that is, the lpOutput parameter is pushed last, to the lowest address). In C-language modules, the C compiler performs this task.