I am trying to break a string with space delimiter but it didn't work,where as with "," it works fine. Can anyone help me with this. Following is the piece of my code.
char x[150];
int a[150];
cin >> x;
int i = 0;
char * pch;
pch = strtok(x, " ");
while (pch != NULL)
{
a[i] = atoi(pch);
cout<< a[i]<<"\t";
pch = strtok (NULL, " ");
i++;
}
input: 12 23 50
output: 12
output with comma separator:12 23 50