比较字符串和包含土耳其语字符的用户输入时,strcmp函数不起作用 [英] strcmp function doesn't work while comparing string and user input which includes Turkish characters

查看:73
本文介绍了比较字符串和包含土耳其语字符的用户输入时,strcmp函数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

char *x="Çankırı";
char *y=malloc(sizeof(char)*25);
scanf("%s",y);

if(strcmp(x,y) == 0)
    printf("A");
else
    printf("%s",y);

我输入Çankırı作为y,但其他部分继续运行。我该如何比较这些字符串?

I enter 'Çankırı' for y, but else part runs. How can I compare these strings?

Windows10,代码块。

Windows10 , codeblocks.

编辑:我找到了一个线索。问题是关于setlocale函数。当我使用setlocale(LC_ALL, TURKISH)时,其中一个字符串不能正常工作(输出不是Çankırı,Ank2r2),如果我使用setlocale(LC_ALL, C),则另一个不能正常工作。我不知道如何解决。

I found a clue. Problem is about setlocale function. When I use setlocale(LC_ALL,"TURKISH"), one of the string doesn't work fine(Output is not Çankırı, Ank2r2), and If I use setlocale(LC_ALL,"C"), other one doens't work fine. I don't know how to fix it.

推荐答案

您可能需要使用接受宽字符的函数。例如:

You probably need to use functions that accept 'wide' characters. For example:

#include <wchar.h>
wchar_t *x=L"Çankırı";
wchar_t y[25];
wscanf(L"%s",y);

if(wcscmp(x,y) == 0)
    wprintf(L"A");
else
    wprintf(L"%s",y);

这篇关于比较字符串和包含土耳其语字符的用户输入时,strcmp函数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆