Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the principle of strcat_s function in C language?

Shulou Source: shulou.com Published: 2022-05-31 10:56:00 09月23日 Update

Today, the editor will share with you the relevant knowledge of what the strcat_s function principle of c language is. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

1. Dst memory space size = target string length + original string site +'\ 0'.

2. Use the sizeof function to get the memory space, and the strlen function to get the string length.

That is to get the size of memory space and the length of the lookup string.

Example

# include "stdafx.h" # include#include#include#include "windows.h" / / error C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _ CRT_SECURE_NO_WARNINGS. See online help for details.#pragma warning (disable: 4996) void main () {char src [1024] = {"strlen strlen + tutorial-strcat_s function"}; char dst [1024] = {"www.codersrc.com"}; / / Note: the second parameter of strcat_s is calculated as the size of the concatenated string, not the original string size or the target string size int len = strlen (src) + strlen (dst) + 1 Printf ("dst:%s before strcat_s\ n", dst); / / strcat_s (dst, len, src); printf ("dst:%s after strcat_s\ n", dst); / / system ("pause"); output result: dst:www.codersrc.comC/C++ tutorial after dst:www.codersrc.comstrcat_s before strcat_s-Please press any key to continue. . . These are all the contents of the article "what is the principle of strcat_s function in c language". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Tags: Characters strings functions size knowledge articles memory space length principles language content parameters tutorials goals different original large site most Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Linux Shulou Technology MySQL Docker