strncat_s、wcsncat_s
string.h:インデックス への移動
ヘッダー ファイル
string.h、mbstring.h
カテゴリ
メモリおよび文字列操作ルーチン、インライン ルーチン
プロトタイプ
errno_t *strncat(char * _RESTRICT dest, rsize_t destmax, const char * _RESTRICT src, rsize_t n);
errno_t *wcsncat(wchar_t * _RESTRICT dest, rsize_t destmax, const wchar_t * _RESTRICT src, rsize_t n);
説明
strncat の代わりとなるもので、セキュリティ機能が強化されています。
1 つの文字列の一部分を別の文字列に付け加えます。
strncat_s は、src から dest の末尾に、最大 n 文字をコピーします。 結果として得られる文字列の最大長は、strlen(dest) + destmax になります。
実行時制約の違反が起きると、dest[0] が NULL 文字に設定されます。
戻り値
成功すればゼロを、成功しなければゼロ以外を返します。
例
#include <string.h>
#include <stdio.h>
int main(void)
{
char destination[25];
char *source = " States";
strcpy_s(destination, 7, "United");
strncat_s(destination, 14, source, 7);
printf("%s\n", destination);
return 0;
}
移植性
| POSIX | Win32 | ANSI C | ANSI C++ | |
|---|---|---|---|---|
|
strncat_s |
+ |
+ |
+ |
+ |
|
wcsncat_s |
+ |