2014-05-20 16:33:16 -04:00
|
|
|
/* strqtok-test.c
|
2014-05-23 16:52:02 -04:00
|
|
|
*
|
|
|
|
* 2014-04-21, Paul Foerster
|
|
|
|
* 2014-05-20, Greg King
|
|
|
|
*
|
|
|
|
* This program tests that strqtok() correctly will parse strings
|
|
|
|
* with quotation marks in them. It should show this list of tokens
|
|
|
|
* from the test strings:
|
|
|
|
*
|
|
|
|
* >This<
|
|
|
|
* > is only <
|
|
|
|
* >a<
|
|
|
|
* >short<
|
|
|
|
* >quoting<
|
|
|
|
* >test , honoring blanks, commas<
|
|
|
|
* >and<
|
|
|
|
* >(4)<
|
|
|
|
* >empty<
|
|
|
|
* ><
|
|
|
|
* ><
|
|
|
|
* ><
|
|
|
|
* ><
|
|
|
|
* >strings, EOT <
|
|
|
|
*
|
|
|
|
* It shouldn't show
|
|
|
|
*
|
|
|
|
* >Bogus token<
|
|
|
|
*
|
|
|
|
*/
|
2014-05-20 16:33:16 -04:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2014-05-23 00:35:19 -04:00
|
|
|
void main (void)
|
2014-05-20 16:33:16 -04:00
|
|
|
{
|
|
|
|
/* b[] and s[] are declared as automatic, not static, variables
|
2014-05-23 16:52:02 -04:00
|
|
|
* because strqtok() will change them.
|
|
|
|
* They must be defined together; and, b[] must be defined first
|
|
|
|
* (because they're copied onto the top-down stack).
|
|
|
|
*/
|
|
|
|
char b[] = "Bogus token ";
|
|
|
|
char s[] = " This , \" is only \"a short "
|
2014-05-20 16:33:16 -04:00
|
|
|
"quoting\"test , honoring blanks"
|
|
|
|
", commas\", and (4) empty \"\"\"\"\"\"\"\" \"strings, EOT ";
|
2014-05-23 16:52:02 -04:00
|
|
|
char* t = strqtok (s, " ,");
|
2014-05-20 16:33:16 -04:00
|
|
|
|
|
|
|
while (t != NULL) {
|
2014-05-23 00:35:19 -04:00
|
|
|
printf (">%s<\n", t);
|
|
|
|
t = strqtok (NULL, " ,");
|
2014-05-20 16:33:16 -04:00
|
|
|
}
|
|
|
|
}
|