you can not use strtok()
with a constant string. And that what you did in your code.
Because the strtok()
edit the string and the constant strings are a read only strings.
To fix your problem, Duplicate your string in a dynamic allocated memory (read-write memory) in this way:
int dummy(char *str)
{
char *mm, *hh;
int len = strlen(str), result;
if (len <= 0 || len > 5)
{
return 0;
}
char *buf = strdup(str); // Modif here
hh = strtok(buf, ":"); // Modif here
while(hh){
printf("%s", hh);
hh = strtok(NULL, ":");
}
free(buf); // Modif here
return result;
}