Ad
  • Default User Avatar

    first point:

    the provided clang installation appears to find a definition of strdup() which ought to return an int,

    When the compiler encounters a function call for which it does not find a function declaration, it assumes the function has this prototype: int func_name ().
    strdup() is sadly not yet part of standard C (it will be added in C23). This is why the compiler does not find it in <string.h> : it is a POSIX extension. you have to #define _GNU_SOURCE before #include <string.h> to make it visible:

    #define _GNU_SOURCE
    #include <string.h>
    

    second point: your code is almost correct, but has 2 mistakes:

    • you are not handling empty strings correctly,
    • you are adding a trailing space at the end of the string
  • Default User Avatar

    next time just use

     --> ``` 
        some code
    again this  --> ``` 
    
  • Custom User Avatar

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