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.
It may seem a bit long but this is because I make a point of returning an array that has the right size instead of returning an array of size n1.
I like the use of goto, it makes it quite readable (allthough all C courses say NOT to use it :-)
Another thing is that you are returning an array that is bigger than necessary which I guess would be ok for performance
but is not optimal in terms of memmory management. If your function was called repateadly on a big arrays it could lead to memmory exhaustion
I guess.
Not here to brag but isn't this kata surprisingly easy to be ranked as 5 kyu ?
I am kind of new to C and this the kata that has been the most easy to solve for me, took me two minutes to complete.
No need for doing math, for minding types, or to even look for yet unknown functions from the standard library, no memory management, no index counting... I am just surprised is all.
Your program seems to assume the shortest word size is 1 but although the instructions says s will not be an empty string, a non empty string can be "(god knows how many whitespaces)" and has no word so I assume the minimum word size can be 0.
How did you know you had use ceil() and not floor ?
This is why I want to be better at maths for.
This solution won't work if n>999 because s char array declared in the loop will have no room for 1000 and more. Since an int can go up to 2,147,483,647, you would need to declare char s[20] for your function to be fully working.
This comment is hidden because it contains spoiler information about the solution
Is it really necessary to cast the return value of calloc to a char* ? Doesn't the assigment make the conversion implicitly ?
This comment is hidden because it contains spoiler information about the solution
In C, it is not said if the string is null terminated, I assume they are because if not I don't see how it's possible to write that function.
I made a quick check before processing the list :
If what you give back is superior to the money you get to keep,
then you know it won't fly. What do you think ?