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.
Lmaooo
lol, this is hilarious
Yes, that did fix it, thank you very much. And thank you for the reminder of bad practice.
there may be other mistakes, but here is the first that i saw:
you did not reserve 1 byte for the nul character (
'\0'
) inccopy
andicopy
, thus thestrcpy()
calls are undefined behavior and anything can happen during program execution. (also, variable-length arrays are bad style and should not be used in clean code)fix this, and see if your solution works
Hi, I'm doing this kata in C. My code runs fine until the "more complex examples with randomness", where the output is just "Expected: Hello World!, but got: (BLANK)". I printed the inputs so that I can run it on my IDE (Codeblocks) and it runs fine, outputting "Hello World!" as expected. The codes are the exact same, so I'm not sure what is wrong. Anybody has any ideas?
Found the issue... it was a mis-reinitialized variable. THanks all!
Wait a minute, I misunderstood your comment. I tried an input of "abcde abcde" and it returned "edcba abcde", didn;t invert the second one.
I tried that and it works, but as soon as there are multiple words with a 5 letter words it skips the 5-letter. For example, "abcde" ==> "edcba", BUT "Just kidding there is still one more" ==> "Just gniddik there is still one more", where it didn't invert the words "there" and "still".
call your function with this input, and see what happens :
"abcde abcde"
also, style notes: every single cast in your code has no effect. you should use casts more sparingly, and in particular never cast the return of
malloc()
: it is not only useless but harmful, as it suppresses type checking by the compiler. it is a remnant of the ancient times in which C did not have avoid *
type, andmalloc()
returned achar *
But then I'm not even sure about that.. doesn't quite make sense if only 5 letter words are not inverted
Yup, unfortunately I'm using all the right statements... so idk if it's a problem with arrays overstepping bounds and erasing the length values.
Thanks a lot. I now understand what the issue was and the code works here as well.
But
trashy_incel
already pointed out the mistake, it's here:On the first iteration,
j
is out of bounds ofcurWord
. IfcurWord.length()
is, for example, 7, your code doescurWord[7]
, while 7 is not a valid index.Is there a way to debug the code here by stepping through all instructions? That's how I debugged it in Visual Studio
prints out 0
or just nothing when not casting it to an int
Loading more items...