4

I have my code set up so that if argc doesn't equal 2 the main function will return 1. Per the specs I thought. But I keep getting the error that I didn't "handle lack of argv[1]".

if (argc != 2) { return 1; }

Am I missing something.

6

GAR, figured it out. I didn't take the details of "your program should yell at you" literally. This works now.

if (argc != 2)

{
    printf("YOU SCREWED UP!");
    return 1;
}
| improve this answer | |
  • I tried what you said, and it still says the same message – BooFluff May 25 '15 at 7:49
  • I tried an it worked. LOL, thanks bro – dexhunter May 16 '16 at 13:35
  • It worked !! Thanks man – user11691 Jun 9 '16 at 23:55
  • Thank you. I thought my issue was that I could not find what the expected output was supposed to be. Turns out I had deleted the "return 1;" line. Thanks, again. – user11232 Jul 5 '16 at 19:01
1

I had the same error until I moved my declared variables AFTER the if...

if (argc !=2)
{
    printf("Oops! Only 2 arguments allowed");
    return 1;
}

int k = atoi(argv[1]);
string p;  
| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .