Ad
  • Custom User Avatar

    Just FYI, you can post your code here in this thread, if you mark your post as spoiler and use markdown code formatting.

    Now about your code: there's a lot going there, and there is a couple of problems with it. But the most important problem is that your solution suffers from buffer overflows. Did you try to run your solution in your local IDE, with all test cases given in sample tests? I changed your solution in two places by adding one character and it passed for me.

    Other problems:

    • returning a static buffer from convertToText is bad,
    • casting away constness in comparator is bad,
    • sizeof(char) is always superfluous and unnecessary,
    • ... some other more or less serious style and performance remarks.
  • Custom User Avatar

    Sorry, but we can't see why either :(

    Maybe if we could see your code we could know why it crashes.

  • Default User Avatar

    g964 is right, you are not reporting the length of your array:

    lg = &num_packets;
    

    does not work like you think it does. It merely changes the address held by lg locally to your function, it is not visible from the outside. It is *lg (the value that lg points to) that you need to assign to.

    Currently, it's just like you had done this:

    void times_two (int x) { x = x * 2; }
    
    int main (void)
    {
      int x = 30;
      times_two(x);
      printf("x = %d\n", x); // x is still 30
    }
    
  • Default User Avatar

    You returned array has a length of 0 (hence {}). Do you fill correctly lg?

  • Default User Avatar

    Question answered.

  • Default User Avatar

    There may be other things, but you have an out-of-bounds access here:

    runners[i] = malloc(sizeof(char) * packet_len);
    ...
    runners[i][packet_len + 1] = '\0';
    

    (also, char unpacked[1000]; when you have no guarantee that the length will be < 1000 is very bad)