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.
as said by phaffywaffle above the line
jaden_case[strlen(jaden_case)] = '\0';
is wrong, because it's tautological. By definition, if a string is nul-terminated,string[strlen(string)] == '\0'
. So you werent nul-terminatingjaden_case
.I cannot see such test case. The only one similar I see is this:
Are you sure you did not modify the sample tests?
Unfortunately, SIGSEGV comes from sample tests, because they have a copy/paste error. Full tests seem to not have the error and they work. You can temporarily fix the error by replacing first assertion (lines 50-55) with:
But stll, the SIGSEGV gets triggered only when your solution is incorrect, and it indeed has a mistake. It does not handle the
sz_out
correctly.getting a
SIGSEGV
is tough because AFAIK you can't tell what caused it until you stop doing it, so examine all places in your code where you attempt to access memory, then consider the possibilities of how that could go wrongYou "report" the number of items in the array via the
nb_uppercase
pointer, upon which you are attempting to allocate memory for the return value. Instead, set*nb_uppercase = (length of array)
, and initialize and allocate the return array with a seperate, new variable name.This comment is hidden because it contains spoiler information about the solution
fair enough, it is now specified in the initial code
The unspecified encoding is an issue tho. Without this information, its not known how to interpred the characters in input.
char
s in C are not Unicode codepoints, they are 8-bit bytes.♠
is the Unicode codepointU+2660
(9824
in decimal) and cannot possibly fit in a 8-bitchar
with any of the most widely used Unicode encodings (you can see how it is represented by various encodings here). Your code accesses the last byte of the string and compares it to the UTF-8 decimal encoding of the codepoint: this cannot possibly work for characters beyond ASCII. In this kata, the encoding is indeed UTF-8, because it is natively supported on Linux, on which Codewars runs. The string"♠"
will be represented by the following bytes in memory:{0xE2, 0x99, 0xA0, 0x00}
. Indexing the string likestring[idx]
gets only one of these bytes, not the whole codepoint. However, one critical property of UTF-8 is that it is retrocompatible with ASCII, and therefore with<string.h>
functions likestrcpy()
andstrcmp()
. Code likestrcmp("♠", "♥");
will work fine. Knowing this, you can craft a better solution.Please use the
question
tag to ask for help by the way, anissue
is a provable bug in the kata.No, it's not the expected behavior, but it's also not what really happens. I would suspect that you are using
printf
without a newline, but it's hard to tell without seeing the code.This comment is hidden because it contains spoiler information about the solution
You can use a print statement at the top of your code.
Can you paste here the test that you are failing? It looks like you are trying to access an element outside the string length.