Formatting and I/O Library Chapter 2
LabWindows/CVI Standard Libraries 2-62 © National Instruments Corporation
String to String
char *s;
char buf[10];
int n;
s = " abc ";
n = Scan (s, "%s>%s", buf); /* result: buf = "abc" */
s = " abc ";
n = Scan (s, "%s>%s[y]", buf); /* result: buf = " abc" */
Remarks
When extracting a substring from a string, Scan skips leading spaces and tabs unless the y
modifier is present.
s = "a b c; d";
n = Scan (s, "%s>%s", buf); /* result: buf = "a" */
s = "a b c; d";
n = Scan (s, "%s>%s[t59]", buf); /* result: buf = "a b c" */
When Scan extracts a substring from a string and the t modifier is not present, the substring is
considered to be terminated by a white space character. To include embedded white space in the
target string, use the t modifier to change the target string termination character. In the second
call to Scan, [t59] changes the termination character to a semicolon (ASCII 59).
s = " abcdefghijklmnop";
n = Scan (s, "%s>%s[w9]", buf); /* result: buf = "abcdefghi" */
s = " abc";
n = Scan (s, "%s>%s[w9]", buf); /* result: buf = "abc "*/
s = " abc"
n = Scan (s, "%s>%s[w9q]", buf); /* result: buf = "abc" */
Remarks
The w modifier can be used to prevent Scan from writing beyond the end of a target string. The
width specified does not include the ASCII NUL that Scan places at the end of the target string.
Therefore, the width specified should be at least one less than the width of the target character
buffer.
When the w modifier is used and the string extracted is smaller than the width specified, the
remaining bytes in the target string are blank-filled. However, if the q modifier is also used,
ASCII NULs fill the remaining bytes.