diff options
Diffstat (limited to 'man3/scanf.3')
-rw-r--r-- | man3/scanf.3 | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/man3/scanf.3 b/man3/scanf.3 index 7934509..3ac97c0 100644 --- a/man3/scanf.3 +++ b/man3/scanf.3 @@ -2,7 +2,7 @@ .\" Copyright 2022 Alejandro Colomar <alx@kernel.org> .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" -.TH scanf 3 2023-07-20 "Linux man-pages 6.05.01" +.TH scanf 3 2023-12-09 "Linux man-pages 6.7" .SH NAME scanf, fscanf, vscanf, vfscanf \- input FILE format conversion .SH LIBRARY @@ -11,23 +11,23 @@ Standard C library .SH SYNOPSIS .nf .B #include <stdio.h> -.PP +.P .BI "int scanf(const char *restrict " format ", ...);" .BI "int fscanf(FILE *restrict " stream , .BI " const char *restrict " format ", ...);" -.PP +.P .B #include <stdarg.h> -.PP +.P .BI "int vscanf(const char *restrict " format ", va_list " ap ); .BI "int vfscanf(FILE *restrict " stream , .BI " const char *restrict " format ", va_list " ap ); .fi -.PP +.P .RS -4 Feature Test Macro Requirements for glibc (see .BR feature_test_macros (7)): .RE -.PP +.P .BR vscanf (), .BR vfscanf (): .nf @@ -36,7 +36,7 @@ Feature Test Macro Requirements for glibc (see .SH DESCRIPTION The .BR scanf () -family of functions scans input like +family of functions scans formatted input like .BR sscanf (3), but read from a .IR FILE . @@ -49,7 +49,7 @@ and parse them later with .BR sscanf (3) or more specialized functions such as .BR strtol (3). -.PP +.P The .BR scanf () function reads input from the standard input stream @@ -58,7 +58,7 @@ and .BR fscanf () reads input from the stream pointer .IR stream . -.PP +.P The .BR vfscanf () function is analogous to @@ -77,7 +77,7 @@ On success, these functions return the number of input items successfully matched and assigned; this can be fewer than provided for, or even zero, in the event of an early matching failure. -.PP +.P The value .B EOF is returned if the end of input is reached before either the first @@ -132,11 +132,27 @@ T{ .BR vfscanf () T} Thread safety MT-Safe locale .TE -.sp 1 .SH STANDARDS C11, POSIX.1-2008. .SH HISTORY C99, POSIX.1-2001. +.SH CAVEATS +These functions make it difficult to +distinguish newlines from other white space, +This is especially problematic with line-buffered input, +like the standard input stream. +.P +These functions can't report errors after the last +non-suppressed conversion specification. +.SH BUGS +It is impossible to accurately know +how many characters these functions have consumed from the input stream, +since they only report the number of successful conversions. +For example, +if the input is "123\en\ a", +.I scanf(\[dq]%d\ %d\[dq], &a, &b) +will consume the digits, the newline, and the space, but not the letter a. +This makes it difficult to recover from invalid input. .SH SEE ALSO .BR fgets (3), .BR getline (3), |