I am trying to tokenize some string sentences. I decided to tokenize one string sentence at a time and save each token to a variable.
I tried using "strcpy(characterArray, aCstring)" but it didn't work. According to cplusplus.com , strtok returns a pointer to an individual token. Here is my code:
char id[30];
string sentence;
getline (i, sentence); // i is the ifstream object reading from a file
char *cString = new char [sentence.length() + 1];
tokenPtr = strtok(cString, ",");
strcpy(id, tokenPtr); // <--- This line of code did not work
Also in your code, do you want to copy sentence into cString, because I don't think you're doing that - you've just allocated the memory for it but not actually copied anything. In fact I wouldn't use new at all but something like: