我尝试解析文本并在其中找到一些字符.我使用下面的代码.它适用于普通字符,如abcdef,但它不适用于öçşğüı. GCC提供编译警告.我该怎么做才能与öçşğüı合作?
#include
#include
#include
int main()
{
char * text = "öçşğü";
int i=0;
text = strdup(text);
while (text[i])
{
if(text[i] == 'ö')
{
printf("ö \n");
}
i++;
}
return 0;
}
警告 :
warning: multi-character character constant [-Wmultichar]
warning: comparison is always false due to limited range of data type [-Wtype-limits]
在while循环中打印char的地址时有10个地址
printf("%d : %p \n",i,text[i]);
0 : 0xffffffc3
1 : 0xffffffb6
2 : 0xffffffc3
3 : 0xffffffa7
4 : 0xffffffc5
5 : 0xffffff9f
6 : 0xffffffc4
7 : 0xffffff9f
8 : 0xffffffc3
9 : 0xffffffbc
而strlen是10.
但是如果我使用abcde:
0 : 0x61
1 : 0x62
2 : 0x63
3 : 0x64
4 : 0x65
而strlen是5.
如果我使用wchar_t进行文本输出
0 : 0xa7c3b6c3
1 : 0x9fc49fc5
2 : 0xbcc3
而strlen是10,wcslen是3.