Go to the first, previous, next, last section, table of contents.


scanf

Syntax

#include <stdio.h>

int scanf(const char *format, ...);

Description

This function scans formatted text from stdin and stores it in the variables pointed to by the arguments. See section scanf.

The format string contains regular characters which much match the input exactly as well as a conversion specifiers, which begin with a percent symbol. Any whitespace in the format string matches zero or more of any whitespace characters in the input. Thus, a single space may match a newline and two tabs in the input. All conversions except c and [ also skip leading whitespace automatically. Each conversion specifier contains the following fields:

Most conversions make use of strtol or strtoul to perform the actual conversions.

Return Value

The number of items successfully matched and assigned. If input ends before first item is assigned, EOF is returned.

Portability

ANSI, POSIX

Example

int x, y;
char buf[100];
scanf("%d %d %s", &x, &y, buf);

/* read to end-of-line */
scanf("%d %[^\n]\n", &x, buf);
/* read letters only */
scanf("[a-zA-Z]", buf);


Go to the first, previous, next, last section, table of contents.