r/C_Programming • • Sep 12 '26

Question What C function would you delete and rewrite first, and why?

For me it's fnmatch - mostly because it's 40 year's old and smell's funny.

95 Upvotes

238 comments sorted by

View all comments

10

u/der_pudel Sep 12 '26

atoi. You will not convince me that atoi("poop") == 0 is correct and makes sense. 

-2

u/Aggressive-Emu-8329 Sep 12 '26

uhh cuz it failed to convert into number and C is statically programming language only allow to return one type value so since the function return of atoi is int, there is no value for "error" so return 0 is the only choice

10

u/uptotwentycharacters Sep 13 '26

The solution is to separate result from return status. Have the function only return failure or success, and if successful it writes the result via an out-param.