The principle and example usage of strcat_s function in C language
This article mainly explains "the principle and example usage of strcat_s function in c language". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn the principle and example usage of strcat_s function in c language.
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. . . At this point, I believe you have a deeper understanding of "the principle and example usage of strcat_s function in c language". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!