0
if (argv[1] == NULL)
{
        printf("Usage: ./caesar key\n");
        return(1);
}

this is the solution before the program received the first statement validate null

3 Answers 3

0

Since argv[1] does not exist, argv[1] is out of bounds and causes a segmentation fault.

Use argc to check if argv[1] exists.

Hope this helps. If it does then please check the tickmark.

0
0

You must declare the return value

int main(int argc, string argv[] and put these sentences after declarated int l, i, rd = 0; char cadena[100], k, cara[2];

the program check the first emtry and validate

0

Start by checking the value of argc. If argc<2, then argv[1] doesn't exist.

Note that if argv[1] doesn't exist, you can't check if it contains anything, including NULL.

Any attempt to access a nonexistent argv[1] will generate a seg fault.

1
  • it's not problem the argument is NULL when you press ./caesar the pointer argv[] received NULL is the real validation if (argv[1] == NULL) { printf("Usage: ./caesar key\n"); return(1); } Commented Feb 26, 2021 at 1:46

You must log in to answer this question.

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