Well, I'm having troubles with Strtok. I read many posts saying that I can't use char * with strtok, but, what can else can I use to split a string (char*)? or do you know some way to use strtok with pointers?
int play(char** matrixGame, char** matrixUser, int rows, int columns, char* input)
{
char * token2;
int x,y;
char * inputPlay;
inputPlay = (char*)malloc(sizeof(char)*10);
token2 = strtok(input, " ");
x = atoi(token2);
token2 = strtok(NULL, " ");
y = atoi(token2);
token2 = strtok(NULL, " ");
strcpy(inputPlay,token2);
}
hope you can help me guys, thanks.
These answer addresses OP's question strtok segmentation fault, another way to split strings?
Also there is another function called strsep
but which is not standardized. Based on your use, you can use it too. (At the cost of portability).
You can write your own version of strtok
throwing away the things you don't like about strtok
.
You can have a good look at this discussion over this thread discussed earlier. The problems like changing the first argument or not working on constant char arrays can be solvable if you implement them for your purpose.