的代码如下:
#include <stdio.h> #include <string> int 取文本长度_字符数(char *s){//代码摘自 精易模块 文本_逐字分割() 可能仅对gbk有效 int c = strlen(s);int n = 1;int z;int leng = 0; while (n<=c){if (n + 1 > c){z = 1;}else{ if (s[n-1]>128){z = 2;}else{if (s[n - 1]!=13){z = 1;} else{if (s[n + 1-1] != 13){z = 2;}else{z = 1;}}} }leng++; n = n + z;}return leng; } int main(){ char str[] = "你好a"; int len = 取文本长度_字符数(str); printf("字符数:%d", len); //输出5 getchar(); return 0; }