Programming language C / C + +_ wcsupr_ S function - unicode string lowercase to uppercase - Introduction to zero basics of C language

Keywords: Algorithm Dynamic Programming security

Programming language C / C + +_ wcsupr_ S function - unicode string lowercase to uppercase - Introduction to zero basics of C language

catalogue

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

  1. Difference between C language array subscript out of bounds and memory overflow
  2. C language uses pointers to traverse arrays
  3. Difference between C language pointer and array
  4. Difference between C language pointer array and array pointer
  5. C language field pointer
  6. C language function value transfer and address transfer
  7. C language function indefinite length parameter
  8. C language function pointer
  9. C language pointer function
  10. C language callback function callback
  11. C language #pragma once
  12. Difference between C language #include < > and #include ""
  13. C language const modifier function parameters
  14. Difference between const and define in C language
  15. C language # operators
  16. C language ## operators
  17. C language__ VA_ARGS__
  18. C language##__ VA_ARGS__
  19. C language function indefinite length parameter##__ VA_ARGS__ Classic case
  20. C language va_start / va_end / va_arg custom printf function
  21. C language main function
  22. C language main function parameter main(int argc, char *argv [])
  23. C language local variables
  24. C language global variables
  25. Differences between global variables and local variables in C language
  26. C language static
  27. C language extern
  28. Difference between C/C++ Unicode and multibyte
  29. C/C++ wprintf output Chinese garbled code
  30. 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

 

Posted by DapperDanMan on Mon, 22 Nov 2021 22:03:55 -0800