I have a main function,
int main (int argc, char **argv)
{}
I’m supposed to pass two different command-line arguments:
argv[1]=IP ADDRESS type
argv[2]=INTEGER type
For example, ./a.out IP-ADDRESS INTEGER. I am calling this binary with some other script.
The problem is while argv[1] is not available it behaves like INTEGER value as argv[1].
How can I put a check in that if argv is type INT don’t make it to the argv[1] or only IP-ADDRESS type is allow in argv[1]?
is more commonly expressed as:
that is,
argvis a pointer to an array of chars. What those chars represent is up to you, but generally these are going to be zero-delimited strings when the program is called on the command-line.If the user does not supply positional parameters then maybe you should be using options. See
getopt().For example:
Sample runs: