Пространства имён
Варианты
Действия

scanf, fscanf, sscanf

Материал из cppreference.com
< c | io

 
 
File input/output
Функции
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Доступ к файлам
Original:
File access
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Прямой ввод / вывод
Original:
Direct input/output
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
fread
fwrite
Неформатированная ввода / вывода
Original:
Unformatted input/output
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Форматированный ввод / вывод
Original:
Formatted input/output
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Позиционирование файла
Original:
File positioning
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ftell
fgetpos
fseek
fsetpos
rewind
Обработка ошибок
Original:
Error handling
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
clearerr
feof
ferror
perror
Операции с файлами
Original:
Operations on files
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
remove
rename
tmpfile
tmpnam
 
Заголовочный файл <stdio.h>
int scanf( const char *format, ... );
(1)
int fscanf( FILE *stream, const char *format, ... );
(2)
int sscanf( const char *buffer, const char *format, ... );
(3)
Читает данные из различных источников, интерпретирует его в соответствии с format и сохраняет результаты в данной мест.
Original:
Reads data from the a variety of sources, interprets it according to format and stores the results into given locations.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
1)
считывает данные из stdin
Original:
reads the data from stdin
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
считывает данные из файла stream поток
Original:
reads the data from file stream stream
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3)
считывает данные с нулевым buffer строку символов
Original:
reads the data from null-terminated character string buffer
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Содержание

[править] Параметры

stream -
Поток входной файл для чтения
Original:
input file stream to read from
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
buffer -
Указатель на завершающуюся нулем строку символов для чтения
Original:
pointer to a null-terminated character string to read from
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
format -
Указатель на завершающуюся нулем строку, определяющую характер, как читать ввод.
Строка формата состоит из пробельных символов (любой одиночный символ пробела в строке формата потребляет все доступные последовательные пробельные символы из входной), без пробелов символы, кроме % (каждый такой символ в формате строки потребляет ровно один идентичный символ из входного) и технические преобразования. Каждая спецификация преобразования имеет следующий формат:
Original:
The format string consists of whitespace characters (any single whitespace character in the format string consumes all available consecutive whitespace characters from the input), non-whitespace characters except % (each such character in the format strings consumes exactly one identical character from the input) and conversion specifications. Each conversion specification has the following format:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • вводный характер %
    Original:
    introductory % character
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • (необязательно) назначения подавляющих * характер. Если этот параметр присутствует, то функция не присвоить результат преобразования в любое получение аргумент.
    Original:
    (необязательно) assignment-suppressing character *. If this option is present, the function does not assign the result of the conversion to any receiving argument.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • (необязательно) целое число (больше нуля), который определяет максимальное' ширины поля, то есть максимальное количество символов, которое функция разрешено потреблять при выполнении преобразования, указанного в текущем спецификации преобразования. Обратите внимание, что% S и% [может привести к переполнению буфера, если ширина не предусмотрено.
    Original:
    (необязательно) integer number (greater than zero) that specifies maximum field width, that is, the maximum number of characters that the function is allowed to consume when doing the conversion specified by the current conversion specification. Note that %s and %[ may lead to buffer overflow if the width is not provided.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • (необязательно)' длина модификатора, который определяет размер принимающего аргумент, то есть фактический тип назначения. Это влияет на точность преобразования и переполнения правил. По умолчанию тип назначения различна для каждого преобразования типов (см. таблицу ниже).
    Original:
    (необязательно) length modifier that specifies the size of the receiving argument, that is, the actual destination type. This affects the conversion accuracy and overflow rules. The default destination type is different for each conversion type (see table below).
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • Преобразование формата
    Original:
    conversion format specifier
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
Следующие спецификаторы формата доступны
Original:
The following format specifiers are available:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Conversion
specifier
Explanation Argument type
length modifier hh h (none) l ll j z t L
% matches literal % N/A N/A N/A N/A N/A N/A N/A N/A N/A
c matches a single character N/A N/A
char*
wchar_t*
N/A N/A N/A N/A N/A
s matches a character string (a sequence of non-whitespace characters)
[set]
соответствует непустая последовательность символов из set символов.
Original:
matches a non-empty sequence of character from set of characters.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Если первый символ из набора ^, то все символы, не в наборе совпадают. Если набор начинается с ] или ^] то ] характера также входит в комплект.
Original:
If the first character of the set is ^, then all characters not in the set are matched. If the set begins with ] or ^] then the ] character is also included into the set.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
d
Совпадает с 'десятичное целое.
Original:
matches a decimal integer'.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Формат числа так же, как ожидается strtol() со значением 10 для base аргумент
Original:
The format of the number is the same as expected by strtol() with the value 10 for the base argument
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
signed char* or unsigned char*
signed short* or unsigned short*
signed int* or unsigned int*
signed long* or unsigned long*
signed long long* or unsigned long long*
N/A
i
Совпадает с 'десятичное целое.
Original:
matches a decimal integer'.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Формат числа так же, как ожидается strtol() со значением 0 для base аргумент
Original:
The format of the number is the same as expected by strtol() with the value 0 for the base argument
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
u
соответствует 'беззнаковое десятичное целое'.
Original:
matches a unsigned decimal integer.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Формат числа так же, как ожидается strtoul() со значением 0 для base аргумент
Original:
The format of the number is the same as expected by strtoul() with the value 0 for the base argument
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
o
соответствует 'восьмеричное целое'.
Original:
matches an octal integer.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Формат числа так же, как ожидается strtol() со значением 8 для base аргумент
Original:
The format of the number is the same as expected by strtol() with the value 8 for the base argument
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
x
Совпадает с 'шестнадцатеричное целое.
Original:
matches an hexadecimal integer'.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Формат числа так же, как ожидается strtol() со значением 16 для base аргумент
Original:
The format of the number is the same as expected by strtol() with the value 16 for the base argument
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
n
возвращает "Количество символов читал до сих пор .
Original:
returns the number of characters read so far'.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Нет входного потребляется. Не увеличивать количество назначения. Если спецификатор имеет назначение подавляющего оператора определена, поведение не определено
Original:
No input is consumed. Does not increment the assignment count. If the specifier has assignment-suppressing operator defined, the behavior is undefined
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
a, A
e, E
f, F
g, G
соответствует "число с плавающей точкой .
Original:
matches a floating-point number'.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Формат числа так же, как ожидается strtof()
Original:
The format of the number is the same as expected by strtof()
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
N/A N/A
float*
double*
N/A N/A N/A N/A
long double*
p
соответствует реализации определены последовательность символов, определяющая 'указатель'.
Original:
matches implementation defined character sequence defining a pointer.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
printf семейство функций следует производить в той же последовательности использования %p формата
Original:
printf family of functions should produce the same sequence using %p format specifier
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
N/A N/A
void**
N/A N/A N/A N/A N/A N/A
Original:
pointer to a null-terminated character string specifying how to read the input.
Строка формата состоит из пробельных символов (любой одиночный символ пробела в строке формата потребляет все доступные последовательные пробельные символы из входной), без пробелов символы, кроме % (каждый такой символ в формате строки потребляет ровно один идентичный символ из входного) и технические преобразования. Каждая спецификация преобразования имеет следующий формат:
Original:
The format string consists of whitespace characters (any single whitespace character in the format string consumes all available consecutive whitespace characters from the input), non-whitespace characters except % (each such character in the format strings consumes exactly one identical character from the input) and conversion specifications. Each conversion specification has the following format:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • вводный характер %
    Original:
    introductory % character
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • (необязательно) назначения подавляющих * характер. Если этот параметр присутствует, то функция не присвоить результат преобразования в любое получение аргумент.
    Original:
    (необязательно) assignment-suppressing character *. If this option is present, the function does not assign the result of the conversion to any receiving argument.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • (необязательно) целое число (больше нуля), который определяет максимальное' ширины поля, то есть максимальное количество символов, которое функция разрешено потреблять при выполнении преобразования, указанного в текущем спецификации преобразования. Обратите внимание, что% S и% [может привести к переполнению буфера, если ширина не предусмотрено.
    Original:
    (необязательно) integer number (greater than zero) that specifies maximum field width, that is, the maximum number of characters that the function is allowed to consume when doing the conversion specified by the current conversion specification. Note that %s and %[ may lead to buffer overflow if the width is not provided.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • (необязательно)' длина модификатора, который определяет размер принимающего аргумент, то есть фактический тип назначения. Это влияет на точность преобразования и переполнения правил. По умолчанию тип назначения различна для каждого преобразования типов (см. таблицу ниже).
    Original:
    (необязательно) length modifier that specifies the size of the receiving argument, that is, the actual destination type. This affects the conversion accuracy and overflow rules. The default destination type is different for each conversion type (see table below).
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • Преобразование формата
    Original:
    conversion format specifier
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
Следующие спецификаторы формата доступны
Original:
The following format specifiers are available:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Conversion
specifier
Explanation Argument type
length modifier hh h (none) l ll j z t L
% matches literal % N/A N/A N/A N/A N/A N/A N/A N/A N/A
c matches a single character N/A N/A
char*
wchar_t*
N/A N/A N/A N/A N/A
s matches a character string (a sequence of non-whitespace characters)
[set]
соответствует непустая последовательность символов из set символов.
Original:
matches a non-empty sequence of character from set of characters.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Если первый символ из набора ^, то все символы, не в наборе совпадают. Если набор начинается с ] или ^] то ] характера также входит в комплект.
Original:
If the first character of the set is ^, then all characters not in the set are matched. If the set begins with ] or ^] then the ] character is also included into the set.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
d
Совпадает с 'десятичное целое.
Original:
matches a decimal integer'.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Формат числа так же, как ожидается strtol() со значением 10 для base аргумент
Original:
The format of the number is the same as expected by strtol() with the value 10 for the base argument
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
signed char* or unsigned char*
signed short* or unsigned short*
signed int* or unsigned int*
signed long* or unsigned long*
signed long long* or unsigned long long*
N/A
i
Совпадает с 'десятичное целое.
Original:
matches a decimal integer'.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Формат числа так же, как ожидается strtol() со значением 0 для base аргумент
Original:
The format of the number is the same as expected by strtol() with the value 0 for the base argument
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
u
соответствует 'беззнаковое десятичное целое'.
Original:
matches a unsigned decimal integer.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Формат числа так же, как ожидается strtoul() со значением 0 для base аргумент
Original:
The format of the number is the same as expected by strtoul() with the value 0 for the base argument
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
o
соответствует 'восьмеричное целое'.
Original:
matches an octal integer.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Формат числа так же, как ожидается strtol() со значением 8 для base аргумент
Original:
The format of the number is the same as expected by strtol() with the value 8 for the base argument
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
x
Совпадает с 'шестнадцатеричное целое.
Original:
matches an hexadecimal integer'.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Формат числа так же, как ожидается strtol() со значением 16 для base аргумент
Original:
The format of the number is the same as expected by strtol() with the value 16 for the base argument
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
n
возвращает "Количество символов читал до сих пор .
Original:
returns the number of characters read so far'.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Нет входного потребляется. Не увеличивать количество назначения. Если спецификатор имеет назначение подавляющего оператора определена, поведение не определено
Original:
No input is consumed. Does not increment the assignment count. If the specifier has assignment-suppressing operator defined, the behavior is undefined
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
a, A
e, E
f, F
g, G
соответствует "число с плавающей точкой .
Original:
matches a floating-point number'.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Формат числа так же, как ожидается strtof()
Original:
The format of the number is the same as expected by strtof()
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
N/A N/A
float*
double*
N/A N/A N/A N/A
long double*
p
соответствует реализации определены последовательность символов, определяющая 'указатель'.
Original:
matches implementation defined character sequence defining a pointer.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
printf семейство функций следует производить в той же последовательности использования %p формата
Original:
printf family of functions should produce the same sequence using %p format specifier
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
N/A N/A
void**
N/A N/A N/A N/A N/A N/A
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
... -
получение аргументов
Original:
receiving arguments
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[править] Возвращаемое значение

Количество получающих аргументы успешно назначен, или EOF если чтение происходит сбой перед первым получает аргумент был назначен.
Original:
Number of receiving arguments successfully assigned, or EOF if read failure occurs before the first receiving argument was assigned.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[править] Пример

[править] См. также

(C99)
(C99)
(C99)
читается форматированный ввод из stdin, поток файла или buffer
помощью переменной список аргументов
Original:
reads formatted input from stdin, a file stream or a buffer
using variable argument list
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(функция) [edit]
получает строку символов из файла потока
Original:
gets a character string from a file stream
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(функция) [edit]
отпечатки отформатировать вывод stdout, поток файл или буфер
Original:
prints formatted output to stdout, a file stream or a buffer
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(функция) [edit]
C++ документация для scanf, fscanf, sscanf