Help with parsing a sentence.
I am writing a function to parse a sentence and print each separate word on a new line.
For some reason, I keep getting a Seg fault. Can anyone please tell me what I am doing wrong?
It is separating the words and printing them each on a new line, but then it Seg faults after the last word is printed.
Any advice would be much appreciated.
Code:
//prototype
void PrintList(char *ptrA[], const int size);
//call in main looks like this
ParseSentence(Buffer3);
//function
void ParseSentence(char *ptrA)
{
char *words[80];
const char delimiters[4] = {' ','.',',',';'};
int size = strlen(ptrA);
words[0] = strtok(ptrA, delimiters);
printf("%s\n", words[0]);
for(int i = 1; i > 0 && i < size - 1; i++)
{
words[i] = strtok(NULL, delimiters);
printf("%s\n", words[i]);
}
}