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.
I really like the idea of this solution; scanning the data pointer around the edge then moving to the inner edge! Seems like everyone else, myself included, did calculations to find the next element to copy instead of just moving it around. This is much easier to read, I would imagine.
I think if the result has all 26 letters then you'd better calloc 27 (not 26) to make room for the
\0
, otherwise ...you too!
Almost identical to mine. As well as the OB1 problem (the final string might be of 27 bytes including the null terminator), there's a second issue: overflow in
letters
.won't suffer from this.
@caelumable, temp is merely a pointer. It points into same chunk of calloced memory that
final
points at.That memory will be freed in the test code.
EDIT: My mistake, the test code doesn't free the returned memory at all. I guess the author wrote code in this way to allow solutions this return references to static variables.
eum....may I ask when dose the temp be destroyed? and why ? the temp didn't declear in the domain of the for loop, why it destroyed after the for loop?
it doesn't matter if he use sizeof(char), as this would only consume compile time and it would become a constant.
temp pointer is incremented in a for loop, if you want to return it you should decrement it same amount of times because, as @status stated, it points to nothing after for loop.
Because temp pointer point to nothing now.
Because temp pointer point to nothing now.
Why not return temp directly?
Why are you returning final?
Nice solution. Some nitpicks:
sizeof(char)
is by definition always1
, so it's kinda redundant to write that instead of just1
.malloc
,calloc
and friends and null terminate strings.realloc(final, temp - final)
in the end so you don't return a buffer that is longer than it needs to be.Dalao...
Damn, nice solution.
My code was ridiculously similar to yours, haha.
Loading more items...