What is the best way to return an error from a function when I'm already returning a value?

前端 未结 8 1894
盖世英雄少女心
盖世英雄少女心 2020-12-13 13:42

I wrote a function in C that converts a string to an integer and returns the integer. When I call the function I also want it to let me know if the string is not a valid num

8条回答
  •  温柔的废话
    2020-12-13 14:13

    The os-style global errno variable is also popular. Use errno.h.

    If errno is non-zero, something went wrong.

    Here's a man page reference for errno.

提交回复
热议问题