Chapter 2 Formatting and I/O Library
© National Instruments Corporation 2-61 LabWindows/CVI Standard Libraries
When locating a real number in a string, Scan skips over white space characters. If a non-
numeric character other than a white space character, +, or - is found before the first numeric
character, the Scan call fails. Thus, Scan fails on the p in p12.3; it leaves the value in x
unmodified and returns zero, indicating that no target specifiers were satisfied.
s = "12.3m";
n = Scan (s, "%s>%f", &x); /* result: x = 12.3, n = 1 */
s = "12.3.4";
n = Scan (s, "%s>%f", &x); /* result: x = 12.3, n = 1 */
s = "1.23e";
n = Scan (s, "%s>%f", &x); /* result: x = ????, n = 0 */
Scan considers the occurrence of a non-numeric character (such as the m in 12.3m) to mark the
end of the real number. A second decimal point also marks the end of the number. However,
Scan fails on "1.23e" because the value of the exponent is missing.
s = "1.2345";
n = Scan (s, "%s>%f[w4]", &x);/* result: x = 1.23, n = 1 */
The w4 modifier specifies that only the first 4 bytes of the string are scanned.
String to Integer and Real
char *s;
int a, n;
double x;
s = "32 1.23";
n = Scan (s, "%s>%i%f", &a, &x);
/* result: a = 32, x = 1.23, n = 2 */
s = "32, 1.23";
n = Scan (s, "%s>%i[x]%f", &a, &x);
/* result: a = 32, x = 1.23, n = 2 */
s = "32, 1.23";
n = Scan (s, "%s>%i%f", &a, &x);
/* result: a = 32, x = ????, n = 1 */
Remarks
After each of the first two calls to Scan, a = 32, x = 1.23, and n = 2 (indicating that two target
specifiers were satisfied). In the second call, the x modifier is used to discard the separating
comma.
In the third call, there is a comma separator after the integer, but the x modifier is absent.
Consequently, Scan fails when attempting to find the real number. x remains unmodified, and
n = 1 (indicating that only one target specifier was satisfied).