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.
🔴 = Unicode Character U+1F534
🟡 = Unicode Character U+1F7E1
🟢 = Unicode Character U+1F7E2
In hexadecimal.
Thanks for your explanation.
I saw the comment, but I forgot the size is specified in the declaration, so I basically was like "you give me an array, but the memory is not allocated yet", which is wrong, thanks!
I am doing codewars fundamentals only right now, in between reading "The C Programming Language", and I am only on chapter 2, so yeah I know nothing about how all this stuff works.
@lowlight
your
malloc()
doesnt do anything, it just leaks memory. it is overwritten by the first pass of yourfor
loop. Re-assigningintegers
inside your function will not affect its value outside of your function. Besides, your are assigning an address to an integer, the compiler most likely warned you about this:This is because
*integers
points to the first element of the array; i.e. to anint
. But even if you had writtenintegers = malloc(...)
, this would make no sense, because the caller would not see the change: through the function call your are given a copy of the address ofintegers
. If you wanted to change whatintegers
point to, your function would need to take anint **
, not anint *
.It is specified by a comment in the initial code, which is still there in your solution:
bruh. its not specified so i calculated the size and allocted that much with malloc
integers
is already preallocated by the tests and it is ensured that it is big enough to hold the result.The
++
just moves the pointer forward.are you dynamically adding more space to the array with the *integers++?
My head hurtie :,)
how to display the color light that?
Beyond instruction portability, there's no guarantee that this will get loaded into an executable page.
This is very creative, well done!
if
words
is an""
, then*(tmp++) = *words; *tmp = 0;
this will set 2 zeros.If each individual test gave the minimum required amount of memory for
letters
, then this solution, on emptywords
, would have exited and written out of memory limits forletters
.??????????? LOL
gcc -m32 ? (solution not suitable for 32 bit architectures?)
Maybe the '1' should be extended to 'uint64_t' instead of 'long'?
If your function type changes in C you'd better rewrite your code however. What if it becomes a string? There is a problem to solve, with specifications, makes no sense to assume if whatever could happen.
I'm thinking of maintaining the code - works for this solution - but not a best practice
Loading more items...