简体   繁体   English

比较字符串和包含土耳其语字符的用户输入时,strcmp函数不起作用

[英]strcmp function doesn't work while comparing string and user input which includes Turkish characters

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

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

I enter 'Çankırı' for y, but else part runs. 我输入y表示“Çankırı”,但其他部分运行。 How can I compare these strings? 如何比较这些字符串?

Windows10 , codeblocks. Windows10,代码块。

EDIT: I found a clue. 编辑:我找到了一个线索。 Problem is about setlocale function. 问题是关于setlocale函数。 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. 当我使用setlocale(LC_ALL,“ TURKISH”)时,其中一个字符串不能正常工作(输出不是Çankırı,Ank2r2),如果我使用setlocale(LC_ALL,“ C”),则另一个不能正常工作。 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM