I am having trouble building a tokenizer. I am new to c++ and was wondering if anyone could help.
When I run the program, I enter the user input as "x = a + 1". When i do this, the only token output is the x
. I want to display "x\n = a\n +\n 1\n"
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
char *text = (char*)malloc ( 40 *sizeof( char ));
cout << "Enter the first arrangement of data." << endl;
cin >> text;
char *token = strtok(text, " ");
while ( token )
{
if ( strlen(token) > 0 )
{
printf(" %s", token);
}
token = strtok(NULL, " ");
}
return 0;
}