C-standard-library-c-function-strncat

提供:Dev Guides
移動先:案内検索

Cライブラリ関数-strncat()

説明

Cライブラリ関数 char strncat(char dest、const char src、size_t n)は、 *src が指す文字列を dest が指す文字列の最後に n 文字まで追加します。 。

宣言

次に、strncat()関数の宣言を示します。

char *strncat(char *dest, const char *src, size_t n)

パラメーター

  • dest -これは、C文字列を含む宛先配列へのポインタであり、追加のヌル文字を含む連結された結果文字列を含むのに十分な大きさでなければなりません。
  • src -これは追加される文字列です。
  • n -これは追加される最大文字数です。

戻り値

この関数は、結果の文字列destへのポインタを返します。

次の例は、strncat()関数の使用法を示しています。

#include <stdio.h>
#include <string.h>

int main () {
   char src[50], dest[50];

   strcpy(src,  "This is source");
   strcpy(dest, "This is destination");

   strncat(dest, src, 15);

   printf("Final destination string : |%s|", dest);

   return(0);
}

次の結果を生成する上記のプログラムをコンパイルして実行しましょう-

Final destination string : |This is destinationThis is source|