This function make a strange error after using it several times and I really can't understand the reason behind it.
char *get_range(char *str,int min,int max){ char *_res=(char *)malloc(sizeof(str)); int cur=0; while (min<max){ _res[cur]=str[min]; min++; cur++; } return _res; } The problem is that after using this function several times, the output comes with additional chars and I don't understand why.
Notice: The additional chars are allway used returned by the function beffor
malloc(sizeof(str));reserves enough memory for a string of 7 characters at most. You probably should change this tomalloc(strlen(str)+1);.sizeof(str)is pointer (char *) size. 2)_resdoesn't null-terminated.