2
4

3 回答 3

4

代码:

 printf("%d\n",(int)strlen("‰")); 

返回值:

 3
于 2013-03-01T07:10:54.660 回答
1

正如 Aki 所建议的,您可以使用 strlen,或者您可以通过以下方式计算字节数:

#include <stdio.h>

int fn(const char *s)
{
    int n = 0;

    if (*s != '\0') {
        do {
            n++;
            s++;
        } while ((*s & 0xc0) == 0x80);
    }
    return n;
}

int main(void)
{
    printf("%d\n", fn("‰"));
    return 0;
}
于 2013-03-01T09:03:20.433 回答
0

sizeof 可以工作。我想使用:

unsigned char a[]="‰"; 
size_t s=sizeof(a)-1;
size_t t=strlen((char*)a);

但在 VC2012 中st是 1。a[0]是 137。另外,我认为正在寻找的正是mblen()

于 2013-03-01T23:46:46.193 回答