I think my program handles lack of argv[1] correctly, yet it fails check50's test. here my code:
if ( argc != 2 ) printf ("usage : ./caesar + key \n"); return 1; 
the issue is that you started your code
int main( int argc, string argv[])
{ int k = atoi(argv[1];
. . . }
/// the mistakes is in the above assignment, if the there is no argv[1] so the OS will report error and terminates the program
so you have not to do k assignment to argv[1] unless you make sure there is
argv[1]
thanks
Mohamed Abdeltawab
The number of command-line arguments cannot be negative. In fact, it cannot even be < 1. See this answer for more details!
If the number of command-line arguments is not 1 (i.e., argc != 2), your program should "print" an error message and "return" an error code of 1.
You need to add your curly brackets (aka braces). Instead of
if ( argc != 2 ) printf ("usage : ./caesar + key \n"); return 1; You should have:
if ( argc != 2 ) { printf ("usage : ./caesar + key \n"); return 1; } printf ("usage : ./caesar + k \n"); Because the instruction code also gives such examples. if (argv[1] == NULL) { printf("Usage: ./caesar key\n"); return(1); } this is the solution before the program received the first statement validate null