mercredi 29 novembre 2017

C: Many if to less lines

For an exercise, I must recode the "ls" function. Currently I'm using if(strcmp to gestionate the flags but I'm wondering if there is another way to do it with less lines. Thanks in advance and there you have my code.

void my_ls(int argc, char *argv[])
{
    if(strcmp(argv[1], "-a") == 0)
        minus_a(argc, argv);
    if(strcmp(argv[1], "-d") == 0)
        minus_d(argc, argv);
    if(strcmp(argv[1], "-F") == 0)
        minus_cap_f(argc, argv);
    multi_ls(argc, argv);
}

Aucun commentaire:

Enregistrer un commentaire