Digital UNIX Diffs - printf(5) Digital UNIX Diffs - printf(5)NAME
printf, fprintf, sprintf - Print formatted output
LIBRARY
Standard C Library (libc.so, libc.a)
SYNOPSIS
#include <stdio.h>
int printf(
const char *format
[,value]...);
int fprintf(
FILE *stream,
const char *format
[,value]...);
int sprintf(
char *string,
const char *format
[,value]...);
PARAMETERS
Specifies a character string combining literal characters with conver‐
sion specifications. Specifies the data to be converted according to
the Points to a FILE structure specifying an open stream to which con‐
verted values will be written. Points to a character array in which
the converted values will be stored.
DIFFERENCESvms-vaxc(5): OpenVMS VAX C vs DEC C Differences
The ANSI C Standard padding rules for the printf(3) routines are dif‐
ferent than the VAX C RTL behavior. The following examples illustrate
the differences:
Example VAX C RTL DEC C RTL
printf("%04.2d", 77); "0077" " 77"
printf("%6.4d", 77); " 77" " 0077" printf("%.2g",
9.876e+2); "9.88e+02" "9.9e+02"
The ANSI C Standard also requires that an empty precision value in a
printf(3) format specifier be treated as a zero precision. The VAX C
RTL ignores an empty precision value as shown in the following example.
Example VAX C RTL DEC C RTL
printf("%-.s", "hello"); "hello" ""
The DEC C RTL will not accept uppercase versions of the printf(3) for‐
mat specifiers. For example, the DEC C RTL will not accept "%D" as a
format specifier, whereas, the VAX C RTL accepts "%D" as a synonym for
the "%d" format specifier. The DEC C RTL prints the letter encoun‐
tered; for example, "%D" produces the letter "D" in the output stream
rather than being processed as an output source.
ultrix-system(5): DEC ULTRIX Operating System Differences
On Digital UNIX, the printf(3) functions do not support the use of the
%D parameter for reading long numbers in decimal format as they do on
DEC ULTRIX. Instead, use the %d or %ld parameter in your print func‐
tions.
In Digital UNIX the printf(3) functions returns the number of dis‐
playable characters in the output (not necessarily the number of bytes)
for a success and a negative number for a failure. The value sprintf(3)
returns for success does not include the terminating '\0' character.
In DEC ULTRIX, printf(3) and fprintf(3) return zero for success and EOF
for failure. The DEC ULTRIX sprintf(3) function returns its first
argument for success and end-of-file (EOF) for failure.
alpha-32bits(5): 32 vs 64 bit Differences
When using the printf() function for long types, you use the length
modifier l (lower-case letter L) with the d, i, o, u, x, and X conver‐
sion characters to specify assignment of type long or unsigned long.
For example, when printing a long as a signed decimal, use %ld instead
of %d. When printing a long as an unsigned decimal, use %lu instead of
%u. If you omit the length modifier, the type is assumed to be int, or
unsigned int, depending on the conversion character. In this case, the
long types are converted to the smaller int types and information might
be lost.
When printing a pointer, use %p. If you want to print the pointer as a
specific representation, the pointer should be cast to an appropriate
integer type long prior to using the desired format specifier. For
example to print a pointer as a long unsigned decimal number, use %lu
as shown:
char *p;
printf ( "%lp = %lu\n", (void *) &p, (long) p);
As a rule, to print an integer of arbitrary size, cast the integer to
long or unsigned long, and use the %ld (unsigned long>>) conversion
character. For example:
printf ("%ld\n", (long)num);
EXAMPLES-------------------------------------------------------------------------
32-Bit Platform | AXP Platform
-----------------------------------+-------------------------------------
| long count;
| long count;
| printf("COUNT:\n");
| printf("COUNT:\n"); printf(" decimal = %d \n", count);| printf("
decimal = %ld \n", count); printf(" unsigned = %u \n", count);|
printf(" unsigned = %lu \n", count); printf(" octal = %o \n",
count);| printf(" octal = %lo \n", count); printf(" hex = %x
\n", count);| printf(" hex = %lx \n", count);
|
-------------------------------------------------------------------------
RELATED INFORMATION
Functions: printf(3), fprintf(3), sprintf(3)CATEGORY INDEXvms-vaxc(5), ultrix-system(5), alpha-32bits(5)
delim off
Digital UNIX Diffs - printf(5)