STRCAT(3) | Linux Programmer's Manual | STRCAT(3) |
名前
strcat, strncat -二つの文字列を連結する書式
#include <string.h>
char *strcat(char * dest , const char * src );
char *strncat(char * dest , const char * src , size_t n );
説明
The strcat() function appends the src string to the dest string, overwriting the terminating null byte ('\0') at the end of dest, and then adds a terminating null byte. The strings may not overlap, and the dest string must have enough space for the result. If dest is not large enough, program behavior is unpredictable; buffer overruns are a favorite avenue for attacking secure programs.strncat() も同様だが、以下の点が異なる。
- *
- src のうち最大 n バイトが使用される。
- *
- src が n バイト以上の場合、 src は NULL 終端されている必要はない。
strcat() と同じく、 dest に格納される結果の文字列は常に NULL 終端される。
src が n バイト以上の場合、 strncat() は dest に n+1 バイトを書き込む ( src からの n バイトと終端の NULL バイトである)。したがって、 dest の大きさは最低でも strlen(dest)+n+1 でなければならない。
strncat() の簡単な実装は以下のような感じであろう:
char*
strncat(char *dest, const char *src, size_t n)
{
size_t dest_len = strlen(dest);
size_t i;
for (i = 0 ; i < n && src[i] != '\0' ; i++)
dest[dest_len + i] = src[i];
dest[dest_len + i] = '\0';
return dest;
}
返り値
strcat() 関数と strncat() 関数は、結果としてできる文字列 dest へのポインタを返す。準拠
SVr4, 4.3BSD, C89, C99.注意
Some systems (the BSDs, Solaris, and others) provide the following function:size_t strlcat(char *dest, const char *src, size_t size);
関連項目
bcopy(3), memccpy(3), memcpy(3), strcpy(3), string(3), strncpy(3), wcscat(3), wcsncat(3)この文書について
この man ページは Linux man-pages プロジェクトのリリース 3.51 の一部である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man-pages/ に書かれている。2012-07-19 | GNU |