National Instruments 320682C Musical Toy Instrument User Manual


 
Formatting and I/O Library Chapter 2
LabWindows/CVI Standard Libraries 2-60 © National Instruments Corporation
Scan considers the occurrence of a non-numeric character (such as the x in 32x1) to mark the
end of the integer.
s = "32567";
n = Scan (s, "%s>%i[w3]", &a); /* result: a = 325, n = 1 */
The w3 modifier specifies that only the first 3 bytes of the string are scanned.
String to Long Integer
char *s;
long a;
int n;
s = "99999";
n = Scan (s, "%s>%i[b4]", &a); /* result: a = 99999, n = 1 */
s = "303237";
n = Scan (s, "%s>%o[b4]", &a); /* result: a = 99999, n = 1 */
s = "ffff";
n = Scan (s, "%s>%x[b4]", &a); /* result: a = 65535, n = 1 */
Remarks
Scan extracts long integers from strings in the same way it extracts integers. The only
differences are that the b4 modifier must be used and the target argument must be a long integer.
See the String to Integer example earlier in this section for more details on using Scan to extract
integers and long integers from strings.
String to Real
char *s;
double x;
int n;
s = "12.3";
n = Scan (s, "%s>%f", &x); /* result: x = 12.3, n = 1 */
s = "-1.23e+1";
n = Scan (s, "%s>%f", &x); /* result: x = -1.23, n = 1 */
s = "1.23e-1";
n = Scan (s, "%s>%f", &x); /* result: x = 0.123, n = 1 */
Remarks
When locating a real number in a string, Scan accepts either floating-point notation or scientific
notation.
s = " 12.3";
n = Scan (s, "%s>%f", &x); /* result: x = 12.3, n = 1 */
s = "p12.3";
n = Scan (s, "%s>%f", &x); /* result: x = ????, n = 0 */