Digital UNIX Diffs - scanf(5) Digital UNIX Diffs - scanf(5)NAME
scanf, fscanf, sscanf - Converts formatted input
LIBRARY
Standard C Library (libc.so, libc.a)
SYNOPSIS
#include <stdio.h>
int scanf(
const char *format
[,pointer]...);
int fscanf(
FILE *stream,
const char *format
[,pointer]...);
int sscanf(
const char *string,
const char *format
[,pointer]...);
PARAMETERS
Specifies the format conversion. Specifies the input stream. Speci‐
fies input to be read. Points to the location to store the interpreted
data.
DIFFERENCESvms-vaxc(5): OpenVMS VAX C vs DEC C Differences
The ANSI C standard-defined behavior for negated scansets in the
scanf(3) function is different from the VAX C RTL behavior. The stan‐
dard requires at least one character to match. For example, the fol‐
lowing code fails if it encounters an empty line:
/* read lines and throw away the newline */ fscanf("%[^0%*c",
&string);
The DEC C RTL requires the code to be implemented as follows:
/* read lines and throw away the newline */ if
(fscanf("%[^0%*c", &string) == 0) fscanf("%*c"); /*
swallow blank-line newline */
ultrix-system(5): DEC ULTRIX Operating System Differences
On Digital UNIX, the scanf(3) functions do not support the use of
uppercase format specifiers, whereas, DEC ULTRIX will accept an upper‐
case specifier as an equivalent for lowercase one. Examples include
the %D, %U, %O and %X format specifiers. If applications use the %D
format specifier to scan in a long number in decimal format, the scan
functions uses the character D as a delimiter rather than a conversion
specification. Instead, use the %d (or %ld), %u, %o and %x, respec‐
tively.
alpha-32bits(5): 32 vs 64 bit Differences
When using the scanf() function for long types, you use the length mod‐
ifier l (lower-case letter L) with the d, i, o, u, and x conversion
characters to specify assignment of type long or unsigned long. For
example, when reading a long as a signed decimal, use %ld instead of
%d. When reading 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 using the l modifier followed by a e, f, or g indicates that the
receiving variable will be treated as a double instead of a float.
As a rule, to read an integer of arbitrary size, cast the integer to
long or unsigned long, and use the %ld (unsigned long) conversion char‐
acter. For example:
scanf ("%ld\n", (long) num);
EXAMPLES-------------------------------------------------------------------------
32-Bit Platform | AXP Platform
-----------------------------------+-------------------------------------
| long count;
| long count;
| scanf("COUNT:\n");
| scanf("COUNT:\n"); scanf(" decimal = %d \n", count); | scanf(" deci‐
mal = %ld \n", count); scanf(" unsigned = %u \n", count); | scanf("
unsigned = %lu \n", count); scanf(" octal = %o \n", count); |
scanf(" octal = %lo \n", count); scanf(" hex = %x \n", count);
| scanf(" hex = %lx \n", count);
|
-------------------------------------------------------------------------
RELATED INFORMATION
Functions: scanf(3), fscanf(3), sscanf(3)CATEGORY INDEXvms-vaxc(5), alpha-32bits(5)
delim off
Digital UNIX Diffs - scanf(5)