I am working on a text RPG and I need a way to parse the user's commands and I think tokenizing the input would be the easiest so I can piece together the bits. However, it is not working well for me. Here is the piece of my code so far:
This is a test running from a tokenizer I got at metalshell.com and I want to get it to parse a user input, which it won't do. It runs and I input text, then it says "Toeknizing Complete" then it ends.
cout << "> ";
cin >> command;
str = strtok(command, " ");
/* extract string from string sequence */
str = strtok(NULL, " ");
/* check if there is nothing else to extract */
if (str == NULL)
cout << "Tokenizing complete\n";
/* print string after tokenized */
printf("%i: %s\n", x, str);
I am fairly new to C++ so I don't know how to fix it. And what do the %i and %s do?
My goal here is that I can parse the string, then, for example, read the first token as "take", then read the second token as "club" and go from there.
Thanks for any help.