Ad
  • Custom User Avatar

    There is this warning when compiling this solution:

    solution.c:10:1: warning: control may reach end of non-void function [-Wreturn-type]
    }
    ^
    1 warning generated.
    

    This solution is not valid, it introduces UB into the program.

  • Default User Avatar

    So I might be missing something but how does it return false if no conditions are true? Is that something intrinsic to c?

  • Default User Avatar

    asprintf() is a Linux function, not in standard C or POSIX. you must either declare it manually, or #define _GNU_SOURCE before you #include <stdio.h>

  • Custom User Avatar

    The tests free it. It's always the case when you must return a heap allocated array / string (you cannot free it yourself: where would you? After return, the statement is not executed, before return then you would return a pointer to something not allocated anymore).

  • Custom User Avatar

    Why is the memory pointed to by r not released at the end of the function

  • Custom User Avatar

    I think if the result has all 26 letters then you'd better calloc 27 (not 26) to make room for the \0, otherwise ...

  • Default User Avatar

    you too!

  • Custom User Avatar

    Almost identical to mine. As well as the OB1 problem (the final string might be of 27 bytes including the null terminator), there's a second issue: overflow in letters.

    while(*s1) letters[*s1++] = 1;
    

    won't suffer from this.

  • Custom User Avatar

    @caelumable, temp is merely a pointer. It points into same chunk of calloced memory that final points at.

    That memory will be freed in the test code.

    EDIT: My mistake, the test code doesn't free the returned memory at all. I guess the author wrote code in this way to allow solutions this return references to static variables.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    eum....may I ask when dose the temp be destroyed? and why ? the temp didn't declear in the domain of the for loop, why it destroyed after the for loop?

  • Custom User Avatar

    it doesn't matter if he use sizeof(char), as this would only consume compile time and it would become a constant.