Printf (LabVIEW Manager Function)

SPrintf, SPrintfp, PPrintf, PPrintfp, FPrintf, LStrPrintf

int32 SPrintf(CStr destCSt, CStr cfmt, ...);

int32 SPrintfp(CStr destCSt, PStr pfmt, ...);

int32 PPrintf(PStr destPSt, CStr cfmt, ...);

int32 PPrintfp(PStr destPSt, PStr pfmt, ...);

int32 FPrintf(File destFile, CStr cfmt, ...);

MgErr LStrPrintf(LStrHandle destLsh, CStr cfmt,...);

Purpose

These functions format data into an ASCII format to a specified destination. A format string describes the desired conversions. These functions take a variable number of arguments. Each argument follows the format string paired with a conversion specification embedded in the format string. The second parameter, cfmt or pfmt, must be cast appropriately to either type CStr or PStr.

SPrintf and SPrintfp

SPrintf prints to a C string, just like the C library function sprintf. sprintf returns the actual character count and appends a NULL byte to the end of the destination C string.

SPrintfp is the same as SPrintf, except the format string is a Pascal string instead of a C string. As with SPrintf, SPrintfp appends a NULL byte to the end of the destination C string.

If you pass NULL for destCStr, SPrintf and SPrintfp do not write data to memory. SPrintf and SPrintfp return the number of characters required to contain the resulting data, not including the terminating NULL character.

PPrintf and PPrintfp

PPrintf prints to a Pascal string with a maximum of 255 characters. PPrintf sets the length byte of the Pascal string to reflect the size of the resulting string. PPrintf does not append a NULL byte to the end of the string.

PPrintfp is the same as PPrintf, except the format string is a Pascal string instead of a C string. As with PPrintf, PPrintfp sets the length byte of the Pascal string to reflect the size of the resulting string.

FPrintf

FPrintf prints to a file specified by the refnum in fd. FPrintf does not embed a length count or a terminating NULL character in the data written to the file.

LStrPrintf

LStrPrintf prints to a LabVIEW string specified by destLsh. Because the string is a handle that might be resized, LStrPrintf can return memory errors just as DSSetHandleSize does.

Special Characters

These functions accept the following special characters:

\bBackspace
\fForm feed
\nNew line, which inserts the system-dependent end-of-line char(s); for example, CR on Mac OS X, NL on Linux, CRNL on DOS)
\rCarriage return
\sSpace
\tTab
%%Percentage character (to print %)

Formats

These functions accept the following formats:

%[-]Left-justifies what is printed; if not specified, the data is right-justified.
[field size]Indicates the minimum width of the field to print into. If not specified, the default is 0. If less than the specified number of characters are in the data to print, the function pads with spaces on the left if you specified -. Otherwise, the function pads on the right.
[.precision]Sets the precision for floating-point numbers, that is, the number of characters after the decimal place. For strings, this specifies the maximum number of characters to print.
[argument size]Indicates the data size for an argument. It applies only to the d, o, u, and x conversion specifiers. By default, the conversion for one of the specifiers is from a 16-bit integer. The flag l causes this conversion to convert the data so the function assumes the data is a 32-bit integer value.
[conversion]You can precede any of the numeric conversion characters (x, o, d, u, b, e, f) by {cc} to indicate that the number is passed by reference. cc can be iB, iW,..., cX, depending on the corresponding numeric type. If cc is an asterisk (*), the numeric type (iB through cX) is an int16 in the argument list.

Conversion Specifiers

These functions use the following conversion specifiers.

Conversion Specifiers and Descriptions

Specifier Description
b Binary integer
c Character
d Decimal integer
e, E Single-precision, floating-point number in scientific notation
f Single-precision, floating-point number
F Double-precision, floating-point number
g, G Double-precision floating-point number in scientific notation
H String handle (LStrHandle)
o Octal integer
p Pascal string (PStr)
P LabVIEW string (LStrPtr)
q Point (passed by value) as %d,%d representing horizontal, vertical coordinates
Q Point (passed by value) as hv(%d,%d) representing horizontal, vertical coordinates
r Rectangle (passed by reference) as %d,%d,%d,%d representing top, left, bottom, right coordinates
R Rectangle (passed by reference) as tlbr(%d,%d,%d,%d) representing top, left, bottom, right coordinates
s C String (null-terminated)
u Unsigned decimal integer
x Hex integer
z Path