contents   index   previous   next



Clib.scanf()

syntax:

Clib.scanf(formatString, variables[, ...])

where:

formatString - specifies how to read and store data in variables.

 

variables - list of variables to hold data input according to formatString.

 

return:

number - input items assigned.

 

description:

This flexible method reads input from the screen, extracts data from it by matching the string to a format string (as described below), and stores the data in the variables which follow the format string. It returns the number of input items assigned; this number may be fewer than the number of parameters requested if there was a matching failure. The format string contains character combinations that specify the type of data expected. The format string specifies the admissible input sequences, and how the input is to be converted to be assigned to the variable number of arguments passed to this function.

 

Characters are matched against the input as read and as it matches a portion of the format string until a % character is reached. % indicates that a value is to be read and stored to subsequent parameters following the format string. Each subsequent parameter after the format string gets the next parsed value takes from the next parameter in the list following format. A parameter specification takes this form (square brackets indicate optional fields, angled brackets indicate required fields):

 

%[*][width]<type>

 

*, width, and type may be:

 

*
suppress assigning this value to any parameter

width
maximum number of characters to read; fewer will be read if white space or nonconvertible character

type
may be one of the following:

 

d, D, i, I
signed integer

u, U
unsigned integer

o, O
octal integer

x, X
hexadecimal integer

f, e, E, g, G
floating point number

c
character; if width was specified then this will be an array of characters of the specified length

s
string

[abc]
string consisting of all characters within brackets; where AZ represents range "A" to "Z"

[^abc]
string consisting of all character NOT within brackets.

 

Modifies any number of parameters following the format string, setting the parameters to data according to the specifications of the format string.

 

see:

Clib.vscanf()

 

 


Clib.vprintf()