Skip to content

Commit ad53b94

Browse files
authored
Merge pull request #3810 from MicrosoftDocs/master
10/4 AM Publishing
2 parents 594336b + 6c6e53b commit ad53b94

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

docs/c-runtime-library/reference/wcstombs-s-wcstombs-s-l.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
---
22
description: "Learn more about: wcstombs_s, _wcstombs_s_l"
33
title: "wcstombs_s, _wcstombs_s_l"
4-
ms.date: "4/2/2020"
4+
ms.date: 09/30/2021
55
api_name: ["_wcstombs_s_l", "wcstombs_s", "_o__wcstombs_s_l", "_o_wcstombs_s"]
66
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"]
77
api_type: ["DLLExport"]
88
topic_type: ["apiref"]
99
f1_keywords: ["wcstombs_s", "_wcstombs_s_l"]
1010
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
1211
---
1312
# `wcstombs_s`, `_wcstombs_s_l`
1413

@@ -137,26 +136,27 @@ This program illustrates the behavior of the **`wcstombs_s`** function.
137136

138137
int main( void )
139138
{
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.";
143142

144143
printf( "Convert wide-character string:\n" );
145144

146145
// Conversion
147146
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
149148

150149
// Output
151150
printf(" Characters converted: %u\n", i);
152-
printf(" Multibyte character: %s\n\n",
153-
pMBBuffer );
151+
printf(" Multibyte character: %s\n\n", pMBBuffer );
154152

155153
// Free multibyte character buffer
156154
if (pMBBuffer)
157155
{
158-
free(pMBBuffer);
156+
free(pMBBuffer);
159157
}
158+
159+
return 0;
160160
}
161161
```
162162

0 commit comments

Comments
 (0)