My program needs to accept a non-negative integer in a command-line argument. I also must use
int main(int argc, string argv[])
to declare main.
My Code:
#include <stdio.h>
#include <cs50.h>
int main(int argc, string argv[])
{
if (argv[1] < 0)
{
printf("Give one non-negative integer.\n");
return 1;
}
}
My problem:
When I input -1
as my command-line argument, my program doesn't printf
or stop running. It goes on to the next block of code. What can I do to fix it (bearing in mind that I need to keep that exact declaration of main), and why is this current code wrong?