C program causing segmentation fault C program causing segmentation fault unix unix

C program causing segmentation fault


The problem is that pOutFile is NULL when you try and print it. Many OSes (libc) doesn't handle this and you're trying to get it to print a variable that doesn't have a value.

Try this:

if (pOutFile != NULL)    printf("pOutFile is [%s]\n",pOutFile);else    printf("pOutFile is NULL\n");

Added:

pOutFile doesn't have a value even when you specified the -o switch because you didn't put a : after the o in the getopt call. Specifically the :s come after the letter. It should be this:

while( (c = getopt(argc, argv, "a:d:i:l:u:o:")) != EOF)


It looks like you're segfaulting on this line:

    printf("pOutFile is [%s]\n",pOutFile);

Judging by your commandline, you're not using a -o switch, so pOutFile remains NULL, but you're trying to printf it.


Missing : is the problem:

while( (c = getopt(argc, argv, ":a:d:i:l:u:o:")) != EOF)                                            ^