sscanf

sscanf is opposite of sprintf. It scans a string, interprets the characters according to the specified format, and convert them into a list of values. It takes two input arguments. The first is the string to be scanned. The second is the format string. The return value is a list of the values it has found from the input string. For example
>> sscanf("adfadf 32 sdf 12.1", "%s %d %s %f")
   
   (adfadf, 32, sdf, 12.1)
If f is a file, then it has the scanf attribute function. For example,
>> f.scanf("%s %d %s %f")
will try to read a string, an integer, and a floating point number from the file (separated by white spaces)). Similarly to fprintf, we can also use
>> fscanf(f, "%s %d %s %f")
where f is the file being scanned.

The following is a list of the conversions that the functions of the scanf family can perform.

Table 11.1: Scanf conversions
Character Type of Value
c single character
d decimal integer
o octal integer
x hexadecimal integer
e, f, g floating point number
s character string
% literal %, no conversion

.

oz 2009-12-22