I need to split line by line. I did it as follows:
int doSegment(char *sentence, int segNum)
{
assert(pSegmenter != NULL);
Logger &log = Logger::getLogger();
char delims[] = "\n";
char *line = NULL;
if (sentence != NULL)
{
line = strtok(sentence, delims);
while(line != NULL)
{
cout << line << endl;
line = strtok(NULL, delims);
}
}
else
{
log.error("....");
}
return 0;
}
I introduce "we are alone. \ Nyes we". and call the doSegment method. But when I debug, I found the sentence parameter: "we are one. \\ nyes we are", and the breakdown failed. Can someone tell me why this happened and what should I do. Anyway, I can use to split the string in C ++. thank!
source
share