Путеводитель по Руководству Linux

  User  |  Syst  |  Libr  |  Device  |  Files  |  Other  |  Admin  |  Head  |



   fscanf.3p    ( 3 )

преобразовать форматированный ввод (convert formatted input)

Примеры (Examples)

The call:

int i, n; float x; char name[50]; n = scanf("%d%f%s", &i, &x, name);

with the input line:

25 54.32E-1 Hamster

assigns to n the value 3, to i the value 25, to x the value 5.432, and name contains the string "Hamster".

The call:

int i; float x; char name[50]; (void) scanf("%2d%f%*d %[0123456789]", &i, &x, name);

with input:

56789 0123 56a72

assigns 56 to i, 789.0 to x, skips 0123, and places the string "56\0" in name. The next call to getchar() shall return the character 'a'.

Reading Data into an Array The following call uses fscanf() to read three floating-point numbers from standard input into the input array.

float input[3]; fscanf (stdin, "%f %f %f", input, input+1, input+2);