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.
Cannot allocate the string statically in C,
free(): invalid pointer
.Please indicate so in the description.
Reading the top comment, I'm wondering if this is a joke.
The idea of using a state machine is a good one, but I think it'd be a better design to only give it one job: get the right coordinates.
Accessing the array with the coordinates should be done outside of this state machine.
The idea of using a state machine is a good one, but yours is way too over-engineered.
Ok so I figured it out. I thought that the function expected
outsz
as the output, but it simply expects you to set it, and to allocate your own array and return it.I think this could be made a lot clearer.
The C translation seems to be bugged, I am unsure what output is expected.
Accessing the same element [0][0] of
mx
in a loop produces undefined behavior.This comment is hidden because it contains spoiler information about the solution
Using the result of a comparison, very clever. I love that.
I think that's my favorite solution so far.
Your tenary operations are difficult to read (though clever), please add some spaces.
I think you should use better variable names.
n
meansn
othing.If you increment the pointer
s
at every loop and dereference it until its value is'\0'
, you don't needlength
,i
or the functionstrlen
, saving you space, performance and readability.Though, if you do that, you will need to ensure that
min
is greater thanlength
by the first comparison. Simply declarelength
anunsigned int
(you can also declare and initializemin
while you're at it), and set the the value to~0
, which sets it at the highest possible value for an integer. This operation is very cheap on the CPU, since you're really only flipping bits, and it guarantees the that the first comparison betweentemp
andmin
works as intended.You can use brackets even on non-arrays.
sentence[1]
and*(sentence + 1)
are equivalent.Aside from that, your idea of synchronizing
sentence
andresult
, to edit a custom arraytemp
and of copyingtemp
overresult
is way more effective than I would have thought. I am genuinely impressed, this is clever.I think that you're being too liberal with the variety of tools that you use.
sprintf
,strcpy
,memset
, the list goes on. You're also using manual pointers.There exist simpler and safer ways of achieving the desired result.
Try to not overuse single-letter variables that way, all declared at the top. It makes it very difficult to understand the program.
Also, instead of writing everything into a scoped
if
statement, you could writeif (!isalpha(result[i])) continue;
And save some precious horizontal and mental space.
Loading more items...