- 论坛徽章:
- 0
|
对应GB2312编码的
- #include <stdio.h>
- #include <string.h>
- int main() {
- const char str_with_hz[] = "a我是一个新手,大家帮帮我,xiexie,大家给个意见,是Unix系统下的。";
- char strs[13][6];
- int index = 0;
- printf("%s\nsize: %d\n“我”字的GB2312编码: %d %d\n", str_with_hz, sizeof(str_with_hz), str_with_hz[1], str_with_hz[2]);
- memset(strs, 0, 13*6);
- for(int i=0; i<6; ++i) {
- int ascii_count = 0;
- for(int j=0; j<12; ++j) {
- if( str_with_hz[index+j] >= 0 ) {
- ++ascii_count;
- }
- }
- if( ascii_count%2 == 0 ) {
- memcpy(strs[i], &str_with_hz[index], 12);
- index += 12;
- }else {
- memcpy(strs[i], &str_with_hz[index], 11);
- index += 11;
- }
- printf("%d, %s\n", index, strs[i]);
- }
- return 0;
- }
复制代码
瞎写的,不对之处请指教!
[ 本帖最后由 funcman 于 2007-8-18 14:24 编辑 ] |
|