Code:
string0 = "This is a string \n";
To convert it to a series of strings, simply scan along the string and at each transition from whitespace to non-whitespace save a pointer to the character at that position. At each opposite transition, replace the whitespace character at that position with a '\0' null terminator.
At the end, you will have accumulated an array of pointers, and the original string will now look like:
Code:
string0 = "This\0is\0 a\0 string\0 \n";
argv[0] ---^ ^ ^ ^
argv[1] ---------+ | |
argv[2] ----------------+ |
argv[3] ----------------------+
argc = 4;
Get a pointer to the start of the string, an array of char *'s in which to collect your string pointers, and a counter of strings found. A couple of temporary variables to remember state at each point along the original string will alow you to detect the transition states. Use the
isspace() function to determine the class of character at each point along the string.
Hope this helps.
--- rod.