cin will only save string inputs up until a space is found. So when
you typed "I Glen 21" at the prompt, it gave up after finding the first
space between "I" and "Glen". The value of test was set to just "I"
and consequently your strtok statements appeared to fail.
One solution is to replace your cin with cin.getline. Your program
would look like this instead:
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
//char test[]="I Glen 21\0";
char* choice;
char* number;
char* title;
char test[100];
cin.getline(test, 100);
choice=strtok(test," ");
title=strtok(NULL," ");
number=strtok(NULL," ");
cout<<choice<<"\n";
cout<<title<<"\n";
cout<<number<<"\n";
}
|