Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C strpbrk不';I don’我没有表现得像预期的那样_C_String_Function_Design Patterns_Output - Fatal编程技术网

C strpbrk不';I don’我没有表现得像预期的那样

C strpbrk不';I don’我没有表现得像预期的那样,c,string,function,design-patterns,output,C,String,Function,Design Patterns,Output,首先我想说,我对C很陌生。 我对strpbrk函数有问题 我的函数得到一个字符串。 如果该字符串包含一个“¼”,它应该做一些事情,如果它包含一个“¾”,它应该做其他事情 static char* format_date_string3(char *string) { printf("Found: %s\n", strpbrk(string, "¼")); if (strpbrk(string, "¼") != NULL) { //do something } el

首先我想说,我对C很陌生。 我对strpbrk函数有问题

我的函数得到一个字符串。 如果该字符串包含一个“¼”,它应该做一些事情,如果它包含一个“¾”,它应该做其他事情

static char* format_date_string3(char *string) {
   printf("Found: %s\n", strpbrk(string, "¼"));
   if (strpbrk(string, "¼") != NULL) {
       //do something
   } else if (strpbrk(string, "¾") != NULL) {
       //do something else
   }
}
我添加printf是为了调试

问题在于,如果字符串为“¼”,则输出为“Found:¼”;如果字符串为“¾”,则输出为“Found:¾”。但是对于“¾”,我希望输出为NULL,因为搜索的模式不在字符串中。为什么不是这样?我怎样才能改变它

是不是因为¼不是“正常”字符

谢谢你的帮助

strpbrk()
不支持多字节编码。

很可能源代码中的和被编码为UTF-8,但在运行时被解释为ASCII

两个字符的UTF-8编码为:

0xC2 0xBC
0xC2 0xBE

由于它们共享一个共同的ASCII“字符”
0xC2
strpbrk()
返回的不是
NULL

谢谢您的回答。这是否意味着我不能对这些字符使用strpbrk?有其他选择吗?@user1894572:这可能有用:谢谢你的快速帮助!这一部分似乎自相矛盾:
如果字符串为“¼”,则为“find:¼”;如果字符串为“¾”,则为“find:¾”。但是对于“¾”,我希望输出为空,因为搜索的模式不在字符串中