Ok, the program I'm working on now involves taking an input string and tokenizing it, by seperating it by spaces. Here's what I've got:
The problem is that whenever I try to run it, I get a segmentation fault. Anybody see what I'm missing here?
Code:
#include <stdio.h> #include <string.h> int main (void) { char *tokenarray[100]; char input[200] = {"Test , Test2"}; char *tokenPtr; int cnt = 0; tokenPtr = strtok(input, " "); while (tokenPtr != NULL) { tokenPtr = strtok(NULL, " "); tokenarray[cnt] = tokenPtr; cnt ++; } for(cnt = 0; cnt < 100; cnt ++); { printf("%s\n", tokenarray[cnt]); } }
Comment