for some reason i get an exception at the first use of strtok() what i am trying to accomplish is a function that simply checks if a substring repeats itself inside a string. but so far i havent gotten strtok to work
int CheckDoubleInput(char* input){
char* word = NULL;
char cutBy[] = ",_";
word = strtok(input, cutBy); <--- **error line**
/* walk through other tokens */
while (word != NULL)
{
printf(" %s\n", word);
word = strtok(NULL, cutBy);
}
return 1;
}
and the main calling the function:
CheckDoubleInput("asdlakm,_asdasd,_sdasd,asdas_sas");
input
should point to a modifiable array, don't call your function asCheckDoubleInput("Hello,_word");
– Delugechar* string = "asdasd,_asdasd"; CheckDoubleInput(string);
still doesnt work – Lavachar string[] = "asdlakm,_asdasd,_sdasd,asdas_sas";
Read the answer I linked with your question. – DelugeDifference between
char *str` andchar str[]
and how both stores in memory?` – Delugechar string[] = "asdlakm,_asdasd,_sdasd,asdas_sas"; CheckDoubleInput(string);"
Read the answer I have linked exactly answer your question. – Delugeconstant string literal
that can't be modified. So I linked the another question to learn differences betweenchar*
andchar[]
– Deluge