Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Hello,
I have never seen the use of
['N'] = "NORTH",
['S'] = "SOUTH",
['E'] = "EAST",
['W'] = "WEST",
before. I didnt even know that this is possible :D. Could you explain what this is and what the benefit of the use is? (I assume it is faster, less code in the if-routine and I can use keywords?)
Thanks in advance.
Because the strtok will replace the delimiter as '\0', but input argument ip is const.
overkill
ugh okay, thx
You do not free
sdup
, therefore leak memory.res
is overwritten byasprintf
, so we need to save previous value ofres
to free memory.You never free
str
, therefore, leak memory.In case of
sz <= 0 || l == 0 || sz > l
you return static string which cannot befree
d. In other cases you return allocated string. This requires from caller additional checks whether to free the returned string or not, so it is not very convenient.In case of
strlen(s) < sz || sz <= 0
you return static string which cannot befree
d. In other cases you return allocated string. This requires from caller additional checks whether to free the returned string or not, so it is not very convenient.Initial value of
*lg == -1
is not documented.Several issues:
return *lg = 0;
-- return value is wrong.char **ret = malloc(sz * sizeof(char**));
-- not correct. Correct ischar **ret = malloc(sz * sizeof(char*));
arr
are freed afterdirReduc
call, the result will become invalid.This comment is hidden because it contains spoiler information about the solution
When you call
pop
, you shouldfree
the string you pop. Otherwise you get memory leak.What if someone
free
strings in the input array right afterdirReduc
call? The result will become invalid and if you will try to read the result, you will get undefined behavior. This cannot be "Best Practice" solution.Why do we need
strdup
here?Loading more items...