Ad
  • Custom User Avatar

    First of all, please mind that this kata uses terrible requirements for its return value, which goes against common C practices. It's not something what you'd do in any kind of C code.

    What you need to do is to return a dynamically allocated array, where each element of such array is a pointer to an individually, dynamically allocated Pair:

    Pair** result = malloc(sizeof(Pair*) * amount_of_returned_pairs);
    
    result[0] = malloc(sizeof(Pair)); // individually allocate each Pair, WHY
    result[0]->first = ...; // assign values to the pair
    result[0]->snd = ...;
    // ... and so on for remaining pairs
    
    return result;
    

    Don't ask why it's done like this, and not just in a normal way of allocating all pairs at once:

    Pair* result = malloc(sizeof(Pair) * amount_of_returned_pairs);
    
    result[0].first = ...; // assign values to the pair
    result[0].snd = ...;
    
    return result;
    

    If you still can't get it to work, i'd suggest asking for help on #c channel of Codewars Discord (and from the start explain what kata you work on, because initially people might not realize how twisted requirements here are), solve it in a higher-level language, or just leave this kata, ignore for now, and come back to it when you get better grasp of memory management in C.