|
1 | 1 | ---
|
2 | 2 | description: "Learn more about: wcstombs_s, _wcstombs_s_l"
|
3 | 3 | title: "wcstombs_s, _wcstombs_s_l"
|
4 |
| -ms.date: "4/2/2020" |
| 4 | +ms.date: 09/30/2021 |
5 | 5 | api_name: ["_wcstombs_s_l", "wcstombs_s", "_o__wcstombs_s_l", "_o_wcstombs_s"]
|
6 | 6 | api_location: ["msvcrt.dll", "msvcr80.dll", "msvcr90.dll", "msvcr100.dll", "msvcr100_clr0400.dll", "msvcr110.dll", "msvcr110_clr0400.dll", "msvcr120.dll", "msvcr120_clr0400.dll", "ucrtbase.dll", "api-ms-win-crt-convert-l1-1-0.dll", "api-ms-win-crt-private-l1-1-0.dll"]
|
7 | 7 | api_type: ["DLLExport"]
|
8 | 8 | topic_type: ["apiref"]
|
9 | 9 | f1_keywords: ["wcstombs_s", "_wcstombs_s_l"]
|
10 | 10 | helpviewer_keywords: ["wcstombs_s function", "string conversion, wide characters", "wide characters, converting", "_wcstombs_s_l function", "wcstombs_s_l function", "characters, converting", "string conversion, multibyte character strings"]
|
11 |
| -ms.assetid: 105f2d33-221a-4f6d-864c-23c1865c42af |
12 | 11 | ---
|
13 | 12 | # `wcstombs_s`, `_wcstombs_s_l`
|
14 | 13 |
|
@@ -137,26 +136,27 @@ This program illustrates the behavior of the **`wcstombs_s`** function.
|
137 | 136 |
|
138 | 137 | int main( void )
|
139 | 138 | {
|
140 |
| - size_t i; |
141 |
| - char *pMBBuffer = (char *)malloc( BUFFER_SIZE ); |
142 |
| - wchar_t*pWCBuffer = L"Hello, world."; |
| 139 | + size_t i; |
| 140 | + char *pMBBuffer = (char *)malloc( BUFFER_SIZE ); |
| 141 | + const wchar_t*pWCBuffer = L"Hello, world."; |
143 | 142 |
|
144 | 143 | printf( "Convert wide-character string:\n" );
|
145 | 144 |
|
146 | 145 | // Conversion
|
147 | 146 | wcstombs_s(&i, pMBBuffer, (size_t)BUFFER_SIZE,
|
148 |
| - pWCBuffer, (size_t)BUFFER_SIZE ); |
| 147 | + pWCBuffer, (size_t)BUFFER_SIZE - 1); // -1 so the appended NULL doesn't fall outside the allocated buffer |
149 | 148 |
|
150 | 149 | // Output
|
151 | 150 | printf(" Characters converted: %u\n", i);
|
152 |
| - printf(" Multibyte character: %s\n\n", |
153 |
| - pMBBuffer ); |
| 151 | + printf(" Multibyte character: %s\n\n", pMBBuffer ); |
154 | 152 |
|
155 | 153 | // Free multibyte character buffer
|
156 | 154 | if (pMBBuffer)
|
157 | 155 | {
|
158 |
| - free(pMBBuffer); |
| 156 | + free(pMBBuffer); |
159 | 157 | }
|
| 158 | + |
| 159 | + return 0; |
160 | 160 | }
|
161 | 161 | ```
|
162 | 162 |
|
|
0 commit comments