hello, im trying to tokenise a string with 2 delimiters , ' '(space ) and ':'
, well how is it possible to understand which delimiters has just used?!
for example consider the following codes:
Code:
#include <cstdio>
#include <cstring>
using namespace std;
int main ()
{
char string1[] ="start: RED X 12";
char * pointer;
string label[10];
printf ("Splitting string start :RED X 12");
pointer = strtok (string1," :");
while (pointer != NULL)
{
/* Note that the delimiters (space, :) */
/* are not themselves tokenized. */
printf ("%s\n", pointer);
pointer = strtok (NULL, " :");
}
return 0;
}
please note that the sample is in C, just to show you what i mean ( just modified a sample when i googled strtok()
ok , here as you see, i want to know how i can understand which delimiter is used so that if ':' is used the first token goes to a varible "Label" stating its a label
and if ' ' is used , the second token goes to a varible "Command" stating its a command, and so on .
the problem is i have no idea when they are used! the only way i can think of it now , is using a search function on the string and if there is a ':' the first token goes to the varible label and the same goes to the command , but you know i think it would be better no to do it this way, that why im asking if it is possible to understand which one is used!
and by the way how is it possible to do it all in a loop that is tokenizing the string?
tanx