Programming language C / C + +_ wcsupr_ S function - unicode string lowercase to uppercase - Introduction to zero basics of C language
catalogue
- I_ wcsupr_ Introduction to s function
- II_ wcsupr_s function practice
- 3, Attention problem
- 3, Guess you like it
Zero foundation C/C + + learning route recommendation: C/C + + Learning directory >> Introduction to basic C language
Zero foundation C/C + + learning route recommendation: C/C + + Learning directory >> C + + object oriented
Zero foundation C/C + + learning route recommendation: C/C + + Learning directory >> C + + design pattern
Zero foundation C/C + + learning route recommendation: C/C + + Learning directory >> C++ STL
Zero foundation C/C + + learning route recommendation: C/C + + Learning directory >> C/C + + Technology
Zero foundation C/C + + learning route recommendation: C/C + + Learning directory >> C/C + + common functions
I_ wcsupr_s Function introduction
stay C / C++ The string is divided into Multibyte string And wide byte string (also known as unicode string). For specific differences, please refer to: Differences between unicode and multibyte;
In C language _strupr_s The function can be used to convert lowercase to uppercase in a multi byte string, and _ wcsupr_s The function is used to unicode To convert lowercase to uppercase in a wide byte string, you need to include a header file string.h ,_ wcsupr_s The function syntax is as follows:
/* *Description: this kind of function is used to convert lowercase to uppercase in unicode string * *Parameters: * [in/out] _Str: Converts uppercase characters in the string to lowercase * [in] _Size: String size after splicing (not the target string size nor the original string size) * *Return value: errno_t is a type newly defined by Microsoft. This type is an integer and represents an error code. Refer to MSDN for details, * If it is 0, there is no error. If it is other values, a value will be thrown; */ //Header file: string.h errno_t _wcsupr_s(char * _Str, size_t _Size);
II_ wcsupr_s Function practice
/******************************************************************************************/ //@Author: ape programming //@Blog (personal blog address): www.codersrc.com //@File:C/C++ _wcsupr_s function – unicode string lowercase to uppercase //@Time:2021/08/25 08:00 //@Motto: no small steps can lead to thousands of miles. No small streams can lead to rivers and seas. The highlights of program life need to be accumulated unremittingly! /******************************************************************************************/ #include "stdafx.h" #include #include #include #include "windows.h" #Include / / setlocale sets the language region of the output text, otherwise the output wchar character contains Chinese garbled code void main() { WCHAR dst[1024] = { L"www.SHUOPYTHON.com" }; //To output Chinese using wprintf, you need to set the language region of the output text, otherwise it is garbled setlocale(LC_ALL, "chs"); //chs represents Chinese, and the header file Locale.h needs to be included wprintf(L"_wcsupr_s before dst:%s\n", dst); _wcsupr_s(dst, wcslen(dst) + 1); wprintf(L"_wcsupr_s after dst:%s\n", dst); system("pause"); } /* Output results: _wcsupr_s Previously dst:www.SHUOPYTHON.com _wcsupr_s After dst:WWW.SHUOPYTHON.COM Please press any key to continue */
III Attention problem
1. _wcsupr_s The second parameter needs to contain '\ 0', otherwise it will crash!
_wcsupr_s(dst, strlen(dst)); //collapse
2. Console output WCHAR / wchar_t ( unicode String) can only be used` wprintf , be not printf ;
Output multi byte string, using printf Function; Output wide byte string, using wprintf Function;
3. If used setlocale Output unicode The string contains Chinese, which must be passed setlocale `Set the function language to Chinese, otherwise it is garbled;
char* p1 = "C/C++course-Ape programming"; //Normal string - Multi byte string wchar_t* p2 = L"C/C++course-Ape programming"; //unicode string - string with modifier L printf("p1 :%s \n", p1); wprintf(L"p2 :%s \n", p2); /* Output: p1 :C/C++Tutorial - Ape programming p2 :C/C++??-???? Please press any key to continue */
Solution: refer to the above example and set the language format
setlocale(LC_ALL, "chs"); //chs represents Chinese, and the header file Locale.h needs to be included
3, Guess you like it
- Difference between C language array subscript out of bounds and memory overflow
- C language uses pointers to traverse arrays
- Difference between C language pointer and array
- Difference between C language pointer array and array pointer
- C language field pointer
- C language function value transfer and address transfer
- C language function indefinite length parameter
- C language function pointer
- C language pointer function
- C language callback function callback
- C language #pragma once
- Difference between C language #include < > and #include ""
- C language const modifier function parameters
- Difference between const and define in C language
- C language # operators
- C language ## operators
- C language__ VA_ARGS__
- C language##__ VA_ARGS__
- C language function indefinite length parameter##__ VA_ARGS__ Classic case
- C language va_start / va_end / va_arg custom printf function
- C language main function
- C language main function parameter main(int argc, char *argv [])
- C language local variables
- C language global variables
- Differences between global variables and local variables in C language
- C language static
- C language extern
- Difference between C/C++ Unicode and multibyte
- C/C++ wprintf output Chinese garbled code
- C/C++ char and wchar_t mutual conversion
No reprint without permission: Ape programming » C/C++ _wcsupr_s function – unicode string lowercase to uppercase
This article is written by blog - Ape programming Ape programming release!
Article source: https://www.cnblogs.com/shuopython/p/15578860.html