I am working on a university assignment and I’ve been wracking my head around a weird problem where my program calls strtok and never returns.
My code looks like:
int loadMenuDataIn(GJCType* menu, char *data)
{
char *lineTokenPtr;
int i;
lineTokenPtr = strtok(data, "\n");
while (lineTokenPtr != NULL) {
/* ... */
}
}
I’ve looked up a bunch of sites on the web, but I cant see anything wrong with the way that I am using strtok and I cant determine why it would my code would get stuck on the line lineTokenPtr = strtok(data, "\n");
Can anyone help me shed some light on this?
(Using OSX and Xcode if it makes any difference)
have you checked the contents of the argument? is it \0 terminated?
the argument that you pass, is it writeable memory? strtok writes to the buffer that it gets as first argument when it tokenizes the string.
IOW if you write