scanf

Table des matières
Retour à l'index

 

NOM

scanf, fscanf, vscanf, vfscanf - Conversion d’entrée de fichier formaté  

BIBLIOTHÈQUE

Bibliothèque C standard (libc, -lc)  

SYNOPSIS

#include <stdio.h>

int scanf(const char *restrict format, ...);
int fscanf(FICHIER *restrict flux,
           const char *restrict format, ...);

#include <stdarg.h>

int vscanf(const char *restrict format, va_list ap);
int vfscanf(FICHIER *restrict flux,
           const char *restrict format, va_list ap);

Exigences de macros de test de fonctionnalités pour la glibc (consulter feature_test_macros(7)) :

vscanf(), vfscanf() :

    _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
 

DESCRIPTION

The scanf() family of functions scans formatted input like sscanf(3), but read from a FILE. It is very difficult to use these functions correctly, and it is preferable to read entire lines with fgets(3) or getline(3) and parse them later with sscanf(3) or more specialized functions such as strtol(3).

La fonction scanf() lit ses données depuis le flux d'entrée standard stdin, fscanf() lit ses entrées depuis le flux pointé par flux.

La fonction vfscanf() est analogue à vfprintf(3) et lit ses arguments depuis le flux pointé par flux en utilisant une liste variable d'arguments de pointeurs, consultez stdarg(3). La fonction vscanf() est analogue à vprintf(3) et lit à partir de l'entrée standard.  

VALEUR RENVOYÉE

En cas de succès, ces fonctions renvoient le nombre d'éléments d'entrée correctement mis en correspondance et affectés. Ce nombre peut être plus petit que le nombre d'éléments attendus, et même être nul, dans le cas d'une erreur précoce de mise en correspondance.

La valeur EOF est renvoyée si la fin de l'entrée est atteinte avant la première conversion réussie ou si un échec de correspondance survient. EOF est également renvoyé si une erreur de lecture survient, auquel cas l'indicateur d'erreur pour le flux (consultez ferror(3)) est positionné et errno est remplie en conséquence  

ERREURS

EAGAIN
Le descripteur de fichier flux sous-jacent est non bloquant et l'opération de lecture bloquerait.
EBADF
Le descripteur de fichier flux sous-jacent n'est pas valable ou bien n'est pas ouvert en lecture.
EILSEQ
La séquence d'octets en entrée ne constitue pas un caractère valable.
EINTR
La lecture a été interrompue par un signal ; consultez signal(7).
EINVAL
Pas suffisamment de paramètres ou bien format est NULL.
ENOMEM
Plus assez de mémoire.
 

ATTRIBUTS

Pour une explication des termes utilisés dans cette section, consulter attributes(7).
InterfaceAttributValeur
scanf(), fscanf(), vscanf(), vfscanf() Sécurité des threadsMT-Safe locale
 

STANDARDS

C11, POSIX.1-2008.  

HISTORIQUE

C99, POSIX.1-2001.  

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.

These functions can't report errors after the last non-suppressed conversion specification.  

BOGUES

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\n a", scanf("%d %d", &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.  

VOIR AUSSI

fgets(3), getline(3), sscanf(3)

 

TRADUCTION

La traduction française de cette page de manuel a été créée par Christophe Blaess <https://www.blaess.fr/christophe/>, Stéphan Rafin <stephan.rafin@laposte.net>, Thierry Vignaud <tvignaud@mandriva.com>, François Micaux, Alain Portal <aportal@univ-montp2.fr>, Jean-Philippe Guérard <fevrier@tigreraye.org>, Jean-Luc Coulon (f5ibh) <jean-luc.coulon@wanadoo.fr>, Julien Cristau <jcristau@debian.org>, Thomas Huriaux <thomas.huriaux@gmail.com>, Nicolas François <nicolas.francois@centraliens.net>, Florentin Duneau <fduneau@gmail.com>, Simon Paillard <simon.paillard@resel.enst-bretagne.fr>, Denis Barbier <barbier@debian.org>, David Prévot <david@tilapin.org>, Frédéric Hantrais <fhantrais@gmail.com>, Grégoire Scano <gregoire.scano@malloc.fr> et Jean-Pierre Giraud <jean-pierregiraud@neuf.fr>

Cette traduction est une documentation libre ; veuillez vous reporter à la GNU General Public License version 3 concernant les conditions de copie et de distribution. Il n'y a aucune RESPONSABILITÉ LÉGALE.

Si vous découvrez un bogue dans la traduction de cette page de manuel, veuillez envoyer un message à


 

Index

NOM
BIBLIOTHÈQUE
SYNOPSIS
DESCRIPTION
VALEUR RENVOYÉE
ERREURS
ATTRIBUTS
STANDARDS
HISTORIQUE
CAVEATS
BOGUES
VOIR AUSSI
TRADUCTION

This document was created by man2html, using the manual pages.
Time: 05:06:30 GMT, September 19, 2025