strcat_s、wcscat_s
string.h:インデックス への移動
ヘッダー ファイル
string.h、_str.h
カテゴリ
メモリおよび文字列操作ルーチン、インライン ルーチン
プロトタイプ
errno_t *strcat(char * _RESTRICT dest, rsize_t destmax, const char * _RESTRICT src);
errno_t *wcscat(wchar_t * _RESTRICT dest, rsize_t destmax, const wchar_t * _RESTRICT src);
説明
strcat、mbscat、wcscat の代わりとなるもので、セキュリティが強化されています。
一方の文字列をもう一方の文字列の末尾に追加します。
strcat_s は、src のコピーを長さが destmax 以下になるように dest の末尾に追加します。 '\0' の後の文字はコピーされません。 追加後の文字列の長さは strlen(dest) + strlen(src) になります。 src と dest が部分的に重なる場合、コピーは行われません。 実行時制約違反が発生した場合、dest[0] には NULL が設定されます。
戻り値
strcat_s は、成功した場合にはゼロを返し、そうでない場合にはゼロ以外を返します。
例
#include <string.h> #include <stdio.h> int main(void) { char destination[25]; char *c = "C++"; char *Embarcadero = "Embarcadero"; strcpy_s(destination, 12, Embarcadero); strcat_s(destination, 20, c); printf("%s\n", destination); return 0; }
移植性
POSIX | Win32 | ANSI C | ANSI C++ | |
---|---|---|---|---|
strcat_s |
+ |
+ |
+ |
+ |
wcscat_s |
+ |
+ |
+ |