vendredi 5 février 2016

Segmentation Fault (Core Dumped) - C Arguments

every time I run the program below in the following way: ./a.out -a -b it runs properly. But if choose to run ./a.out -a, I result in a segmentation fault (core dumped). Is there any way I can fix this?

int main(int argc, char *argv[])
{
    if (argc > 1)
    {
        if (strcmp(argv[1],"-a") == 0)
        {...
        if (strcmp(argv[2],"-b") == 0)
        {...}
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire