is this somewhat what your looking for for question 1:
Code:
#include <stdio.h>
#include <string.h>
int main(void)
{
char* sentence = "one two three four";
char* word[4];
int i = 0;
word[i] = strtok(sentence," ");
while (word[i] != NULL)
{
i++;
word[i] = strtok(NULL, " ");
}
for (i = 0; i < 4; i++)
printf("word[%d] = %s\n",i,word[i]);
return 0;
}
for question 2 here is an example, if im understanding:
Code:
#include <stdio.h>
#include <string.h>
int main(void)
{
char* word1 = "hi"; //tokenized string
char* word2 = "10"; //tokenized string
char* num = "10"; // number to search for
// strcmp returns zero if the two strings are equal
printf("%d\n",strcmp(word1,num));
printf("%d\n",strcmp(word2,num));
return 0;
}
your using C functions (strtok and strcmp).. is this really a C++ program? if your using actual C++ String objects, it would be easier to just use all C. If you have to stick with C++, im sure there are better ways to do this that are C++-specific.. check it out.