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.
This comment is hidden because it contains spoiler information about the solution
Wasn't the point of the problem to add floats and integers?
I thought pow only accepted doubles? I see it works, I am just not quite sure why. Wouldn't there be a danger of pow() returning a double just below the proper integer and then by casting it to an int, it would round down it in the result?
but the array is an integer??
Really neat way to iterate over the digits in reverse order using modulo and division by 10! Impressed!
After testing ang googling, I must admit that you are right, thank you for pointing that out.
Not correct, since floor does return the same value if the input is a round number. Just googled it. Just writing it down here for newbies like me, who read your comment and wonder if thats true.
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!
IMHO, there is a problem for n=10, n=100, n=1000 (...) since in those cases floor(log10(n))+1 won't return the right number of digits.
umm, maybe no? because they initialized the array as integer.
I am very impressed - a very clever solution! My solution took me a while and I wrote 60 lines in total (adding comments explaining everything). Your solution is a lot better, but mine is more readable, in my opinion.
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?