+ 2

[case solved] Warnings in C code with using strdup()

https://code.sololearn.com/cUBwKhWJ5BAr/?ref=app I get some warnings in the attached code and I have no clue how to get rid of them. Despite that the desired output seems correct. Can I get a hint in order to remove the warnings.

8th Oct 2023, 11:36 AM
Jan Markus
2 Answers
+ 2
Maybe extern char* strdup(const char*); as suggested here: https://stackoverflow.com/questions/26284110/strdup-confused-about-warnings-implicit-declaration-makes-pointer-with#26284172 From skimming the thread, it looks like the function is not part of the standard and depending on how strict the compiler is, we get a warning.
8th Oct 2023, 11:48 AM
Lisa
Lisa - avatar
+ 2
Thank you Lisa for the hint. By using extern char* strdup(const char*); right after the #include directives, as in your mentioned stackoverflow thread suggested, the code runs without warnings. 🙂👍
8th Oct 2023, 12:19 PM
Jan Markus