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.
Unfortunately, in C and C++ things are not that easy.
Invalid memory access is defined in C++ as a cause of undefined behaior, and this can mean anything. In your case, your solution writes outside of the result buffer and modifies something which is later on used to calculate reference solution, or to print the message, or anything else. When undefined behavior happens, there are no guarantees anymore: anything can change, anything can break, even things apparently unrelated.
If I were to guess,
sprintf
puts null terminator right behind your buffer, and probablyg
variable happens to be located there on the stack, messing up further computations. But it's just guessing, and it can be wrong or can change from run to run.From all the things which are wrong with your solution, the wrongest ones are probably buffer overflow and missing includes.
Seeing your code would help too.
C++ tests seem to be fine.