[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
To convert text input to a numeric value, it is often convenient to use the
standard scanf
, fscanf
, or sscanf
functions. Each of
these functions requires you to specify the data type as part of the “format”
string (for example, to read an integer and store it as an int
, you
might write scanf("%d", &x)
, but to store it as a long int
, you
might write scanf("%ld", &x)
).
As with the printf
-style macros described in the previous section, the
macros listed below can be used to convert a string to a WFDB_Sample
,
WFDB_Time
, WFDB_Frequency
, or WFDB_Gain
value, regardless
of which standard C data types these represent. Each macro expands to a string
constant (such as "d"
or "ld"
), which does not include the
leading ‘%’ character. For example, to read a table of time and sample
values, we might write:
WFDB_Time t; WFDB_Sample v[2]; char buf[1000]; while (fgets(buf, sizeof(buf), stdin)) { if (sscanf(buf, "%"WFDB_Sd_TIME"%"WFDB_Sd_SAMP"%"WFDB_Sd_SAMP", &t, &v[0], &v[1]) == 3) { putvec(v); } } |
The following macros are defined in ‘<wfdb/wfdb.h>’:
Macro | Argument type | Format |
---|---|---|
WFDB_Sd_SAMP | WFDB_Sample * | Base 10 |
WFDB_Si_SAMP | WFDB_Sample * | Base 8, 10, or 16 |
WFDB_So_SAMP | WFDB_Sample * | Unsigned base 8 |
WFDB_Su_SAMP | WFDB_Sample * | Unsigned base 10 |
WFDB_Sx_SAMP | WFDB_Sample * | Unsigned base 16 |
WFDB_SX_SAMP | WFDB_Sample * | Unsigned base 16 |
WFDB_Sd_TIME | WFDB_Time * | Base 10 |
WFDB_Si_TIME | WFDB_Time * | Base 8, 10, or 16 |
WFDB_So_TIME | WFDB_Time * | Unsigned base 8 |
WFDB_Su_TIME | WFDB_Time * | Unsigned base 10 |
WFDB_Sx_TIME | WFDB_Time * | Unsigned base 16 |
WFDB_SX_TIME | WFDB_Time * | Unsigned base 16 |
WFDB_Se_FREQ | WFDB_Frequency * | Decimal |
WFDB_SE_FREQ | WFDB_Frequency * | Decimal |
WFDB_Sf_FREQ | WFDB_Frequency * | Decimal |
WFDB_Sg_FREQ | WFDB_Frequency * | Decimal |
WFDB_SG_FREQ | WFDB_Frequency * | Decimal |
WFDB_Se_GAIN | WFDB_Gain * | Decimal |
WFDB_SE_GAIN | WFDB_Gain * | Decimal |
WFDB_Sf_GAIN | WFDB_Gain * | Decimal |
WFDB_Sg_GAIN | WFDB_Gain * | Decimal |
WFDB_SG_GAIN | WFDB_Gain * | Decimal |
(The ‘x’ and ‘X’ formats are equivalent, as are the ‘e’,
‘E’, ‘f’, ‘g’, and ‘G’ formats, and are provided for
symmetry with printf
. For more information, see the documentation of
your C compiler.)
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] |
PhysioNet (wfdb@physionet.org)