lundi 29 juin 2015

strcasecmp() : A Non-Standard Function?


The other day I created a post over at CodeReview. One person who answered my question suggested that I refrain from using strcasecmp() because the "function is non-standard [and] this makes [my] code non-portable." This is how I used it:

int playGame()
{

    char scanned[3];
    printf("Do you wish to play tick-tack-toe?\n");
    scanf("%s", scanned);
    if(strcasecmp(scanned,"yes")==0)
        startGame();

    else
    {
        if (strcasecmp(scanned,"no")==0 || strcasecmp(scanned,"nah")==0 || strcasecmp(scanned,"naw")==0)
        {
            printf("That's too bad!/nThis program will now end.");
            return 1;
        }
        printf("Not valid input!/nThis program will now end.");
        return 1;
    }
return 0;
}

Can someone explain more in-depth and why strcasecmp() has these limitations?


Aucun commentaire:

Enregistrer un commentaire