Hi everyone,
I am basically going to be picking apart a c-string that contains words and putting ONLY the unique words in a 2D array of char, in such way that there will be 1 word per row in the 2D array. But how do you put the token (word) in one row of the two dimensional array?
char str[101]="" ; //This is the array where i am picking the words from
char twoDarray[101][16] = {}; //This is where the unique words of str are going
//to be placed, i unique word per row
while (!read.eof())
{
read.getline(str,100,'\n');
char *pch;
pch = strtok (str, " , .");
while (pch !=NULL)
{
cout<<"token: "<<pch<<endl;
pch = strtok (NULL, " ,.");
twoDarray[0][0]= pch; //*I know this part is wrong, how do you do this part??
}
}
what i want to do is place the first
token from str in the first row of the twoDarray and then put second token in the next row, and so on.
Line 17 would be: strcpy(twoDarray[0], pch); // Take care that the length of pch is < 16! But I'm not sure if it actually is what you want. It's practically a 1d array with c-strings
But why not using std::string? They're way more convenient...