int main(void)
{
char *text = (char*)malloc ( 100 *sizeof( char));
cout << "Enter the first arrangement of data." << endl;
cin.getline(text, 100);
char *token = strtok(text, " ");
char *data = (char*)malloc ( 100*sizeof( char));
while ( token != NULL )
{
if (strlen(token) > 0)
{
cout << token << endl; // to test if the token is correct so far.
data[Tcount++] = *token;
}
token = strtok(NULL, " ");
}
for(i = 0; i < Tcount; i++)
{
cout << data[i] << endl;
}
For some reason when i enter in a user input of xp = a + 1, the output of data[i] is:
x
=
a
+
1
Do you know why the first token (should be xp) is only being stored in data[] as x?
Thanks.