I am checking if user enters the correct number and type of cmd arguments when calling main.
I thought it would be a great idea to write a function, which prints out some text, so I can reuse it when checking for NULL pointers. I included <errno.h>.
void errcall() { perror("Error printed by perror()"); exit(EXIT_FAILURE); } Then I wrote a function to check if arguments are right and sufficient.
void err_cmd_handle(int argc_input) { if(argc_input==1 || argc_input>2) errcall(); } When I call this in main, giving int argc as an argument to err_cmd_handle(), then I get a success, even when I did not give any arguments besides starting the program. Why does the condition fail to check correctly?
int main(int argc,char* argv[]) { err_cmd_handle(argc); return 0; }
errnomight have a useful value when you callerrcall?errno, then it is valid to checkerrno. It is not a general purpose error handling support - it is for reporting errors from the standard library.if(argc_input==1 || argc_input>2)apparently fails. Your question cannot be answered without further information and investigation because it is implausible and is more likely an observation error.