Ad
  • Custom User Avatar

    Lol I'm the same way. I enjoy seeing these one line solutions, though, because it helps me learn how to write more efficient code

  • Custom User Avatar
    • you do not allocate enough memory in all cases : "zz" -> "26 26" which needs 6 bytes, you do allocate 6, but since your solutions has a trailing space which is then erased, you need 7 bytes. Currently you are writing out-of-bounds in this case
    • you return a string literal ("") when there are no letters in the input. the tests expect a heap-allocated string, so they will crash when they try to free() the string literal
    • you use strcat() and strncat() on unitialized memory. these functions look for a null byte to start writing; the memory returned by malloc() is NOT 0-initialized; neither are local (stack) variables like str_num, unless you explicitely initialize them with char str_num[4] = {0}. str(n)cat() will keep scanning the memory until it finds a 0 byte, so your program is unpredictable
  • Custom User Avatar

    I have spent hours upon hours on this and the kata says it's getting invalid memory address, while on my own compiler it works completely fine. I'm really pissed off, none of this makes sense

  • Custom User Avatar

    It's very simple, although it contains a magic number which isn't great practice unless if it's self-explanatory. The 3 here is self-explanatory but the 2 is not. Things like this should be labeled with a comment or set as a variable.

  • Custom User Avatar

    imo well it depends on the situation actually but unfortunately i think it is difficult to actually return a literal with a zero in front since some languages like python prohibit base 10 integers with leading zeros
    ofc its nice to remember that for example an int literal is 32 bits long in java and that there are leading zeros there but i think for the sake of this exercise it is better to have the ints without leading ints

  • Custom User Avatar

    "Make it green, than make it clean" I feel like is a reference from Undertale

  • Custom User Avatar

    I think it's not necessary for 0201 to be 201

  • Custom User Avatar

    How are we suppose to modify a paramater when it's a constant

  • Custom User Avatar
  • Custom User Avatar

    I'll agree with this, I believe the author needs to give a much better explanation

  • Custom User Avatar

    I kind of forget to do simple logic like this, I just like using for loops similar to how majority of C is operated