9.21-width string Speech Recognition

Source: Internet
Author: User
Width:
 
 
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <locale.h>
  5. int main()
  6. {
  7. Char STR [10] = "xuanyuan ";
  8. printf("%d,%d\n", sizeof(str), strlen(str));//10,4
  9. Printf ("% d \ n", sizeof (""); // 5

  10. Printf ("% C \ n", STR [0], STR [1]); // Xuan
  11. Printf ("% C \ n", STR [0], STR [1]); // garbled

  12. Printf ("% d, % d \ n", sizeof ("hello"), sizeof (L "hello"); // 6 12

  13. Char * P = "Hello tianchao ";
  14. Wchar_t * PW = l "Hello tianchao ";
  15. Printf ("% s \ n", P); // Hello tianchao
  16. // Error output of wide characters:
  17. Printf ("% s \ n", PW); // H (incorrect output)
  18. Printf ("% ls \ n", PW); // Hello (incorrect output)
  19. Printf (L "% s \ n", PW); // No output
  20. Printf (L "% ls \ n", PW); // No output
  21. // Correct output:
  22. // 1: must contain locale. H 2: Must be set local language 3: ls is to process wide characters
  23. Setlocale (lc_all, "ZH-CN"); // Simplified Chinese
  24. Printf ("% ls \ n", PW); // Hello tianchao (note that this sentence can be correctly printed in setlocale)
  25. Wprintf (L "% ls \ n", PW); // Hello tianchao
  26. return 0;
  27. }


Wide character strlen sizeof:
 
 
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <string.h>
  4. int main()
  5. {
  6. Wchar_t wstr [10] = l "Liu Wei ";
  7. printf("%d\n", sizeof(wstr));//20
  8. printf("%d\n", strlen(wstr));//4
  9. Printf ("% d \ n", sizeof ("Liu Wei"); // 5
  10. Printf ("% d \ n", strlen ("Liu Wei"); // 4
  11. Printf ("% d \ n", sizeof (L "Liu Wei"); // 6
  12. Printf ("% d \ n", strlen (L "Liu Wei"); // 4
  13. return 0;
  14. }




From Weizhi note (wiz)

9.21-width string Speech Recognition

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.