![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Once you have moved the next line into the
input_buffer
array, you can, if you want, treat input_buffer
as a source of characters in place of your
keyboard or a file. The appropriate function is sscanf
, for
string scan formatted. The sscanf
function
is just like the scanf
function, except that there is an extra
argument that identifies the character string to be read from.
Suppose, for example, that your input data may include occasional comments, marked by semicolons, as in the following example:
F-BLD 3.3 300 ; Merger likely T-GG 2.5 400 AX-FLY 9.9 100 AB-CH11 10.1 100 ; Court action imminent C-IBM 5.0 200
Once you have moved a line of text into the input_buffer
array, you
can use sscanf
to pick up the description, price, and
number of shares traded, placing the description in another buffer named
description_buffer
:
sscanf (input_buffer "%s%lf%i", description_buffer, &price, &number);
Thus, the description, price, and number of shares traded are read from the input buffer; the remaining comment, if any, is ignored.