I do get the correct value with getNToken(), but when I try to free the memory it hangs.
char* getNToken(const char* str, const char* delim, const int pos)
{
char* tmp = malloc(strlen(str)+1);
strcpy(tmp,str);
int pos_actual = 0;
tmp = strtok(tmp,delim);
while(pos_actual < pos)
{
tmp = strtok(NULL,delim);
pos_actual++;
}
return tmp;
}
int main()
{
char* d = getNToken("aaa,bbb,ccc",",",1);
printf("%s\n",d);
free(d);
return 0;
}