Skip to content

string -> stringBuffer on strcpy_s... page #2993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions docs/c-runtime-library/reference/strcpy-s-wcscpy-s-mbscpy-s.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,19 @@ Unlike production quality code, this sample calls the secure string functions wi

int main(void)
{
char string[80];
char stringBuffer[80];

strcpy_s(string, _countof(string), "Hello world from ");
strcat_s(string, _countof(string), "strcpy_s ");
strcat_s(string, _countof(string), "and ");
strcat_s(string, _countof(string), "strcat_s!");
strcpy_s(stringBuffer, _countof(stringBuffer), "Hello world from ");
strcat_s(stringBuffer, _countof(stringBuffer), "strcpy_s ");
strcat_s(stringBuffer, _countof(stringBuffer), "and ");
strcat_s(stringBuffer, _countof(stringBuffer), "strcat_s!");

printf("String = %s\n", string);
printf("stringBuffer = %s\n", stringBuffer);
}
```

```Output
String = Hello world from strcpy_s and strcat_s!
stringBuffer = Hello world from strcpy_s and strcat_s!
```

When building C++ code, the template versions may be easier to use.
Expand All @@ -173,20 +173,20 @@ When building C++ code, the template versions may be easier to use.

int main(void)
{
wchar_t string[80];
wchar_t stringBuffer[80];
// using template versions of wcscpy_s and wcscat_s:
wcscpy_s(string, L"Hello world from ");
wcscat_s(string, L"wcscpy_s ");
wcscat_s(string, L"and ");
wcscpy_s(stringBuffer, L"Hello world from ");
wcscat_s(stringBuffer, L"wcscpy_s ");
wcscat_s(stringBuffer, L"and ");
// of course we can supply the size explicitly if we want to:
wcscat_s(string, _countof(string), L"wcscat_s!");
wcscat_s(stringBuffer, _countof(stringBuffer), L"wcscat_s!");

std::wcout << L"String = " << string << std::endl;
std::wcout << L"stringBuffer = " << stringBuffer << std::endl;
}
```

```Output
String = Hello world from wcscpy_s and wcscat_s!
stringBuffer = Hello world from wcscpy_s and wcscat_s!
```

## See also
Expand Down