I have been having some problems with strtok.
I'm not very experienced in C/C++ so I'm not used to using strtok.
the code I have is this:
char *cmnd;
string cmd[100];
char inpt[81];
while(1)
{
cout << "statsh$: ";
cin.getline(inpt,' ');
cmnd = strtok(inpt," ");
int c = 0;
while(cmnd != NULL)
{
cmd[c] = cmnd;
cout << cmd[c] << endl;
c++;
cmnd = strtok(NULL, " ");
}
cout << c << endl;
if(cmd[0] == "exit")
{
break;
}
for(int i=0; i < c; i++)
{
cout<< cmd[i] << endl;
}
}
The thing is here, that if I type out 8 or more words spaces between each, this program goes haywire and runs over and over the prompt statsh$ until it crashes.
If i enter a a a a a a a a a, as a single char with spaces it will take that just fine however. I have no idea what is going on with this strtok crapola. If someone could help me I would much appreciate it.