小编Sup*_*GoA的帖子

strcasecmp():非标准函数?

前几天我在CodeReview上创建了一个帖子.一个回答我问题的人建议我不要使用strcasecmp()因为"函数是非标准的[并且]这使得[my]代码不可移植." 这就是我使用它的方式:

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;
}
Run Code Online (Sandbox Code Playgroud)

有人可以更深入地解释为什么strcasecmp()有这些限制?

c string comparison

8
推荐指数
2
解决办法
1万
查看次数

标签 统计

c ×1

comparison ×1

string ×1