Width:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <locale.h>
int main()
{
Char STR [10] = "xuanyuan ";
printf("%d,%d\n", sizeof(str), strlen(str));//10,4
Printf ("% d \ n", sizeof (""); // 5
Printf ("% C \ n", STR [0], STR [1]); // Xuan
Printf ("% C \ n", STR [0], STR [1]); // garbled
- Printf ("% d, % d \ n", sizeof ("hello"), sizeof (L "hello"); // 6 12
Char * P = "Hello tianchao ";
Wchar_t * PW = l "Hello tianchao ";
Printf ("% s \ n", P); // Hello tianchao
// Error output of wide characters:
Printf ("% s \ n", PW); // H (incorrect output)
Printf ("% ls \ n", PW); // Hello (incorrect output)
Printf (L "% s \ n", PW); // No output
Printf (L "% ls \ n", PW); // No output
// Correct output:
// 1: must contain locale. H 2: Must be set local language 3: ls is to process wide characters
Setlocale (lc_all, "ZH-CN"); // Simplified Chinese
Printf ("% ls \ n", PW); // Hello tianchao (note that this sentence can be correctly printed in setlocale)
Wprintf (L "% ls \ n", PW); // Hello tianchao
return 0;
}
Wide character strlen sizeof:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
int main()
{
Wchar_t wstr [10] = l "Liu Wei ";
printf("%d\n", sizeof(wstr));//20
printf("%d\n", strlen(wstr));//4
Printf ("% d \ n", sizeof ("Liu Wei"); // 5
Printf ("% d \ n", strlen ("Liu Wei"); // 4
Printf ("% d \ n", sizeof (L "Liu Wei"); // 6
Printf ("% d \ n", strlen (L "Liu Wei"); // 4
return 0;
}
From Weizhi note (wiz)
9.21-width string Speech Recognition