XINU
Functions
strncat.c File Reference

文字列s1の末尾に文字列s2をN文字(Byte)分、結合する。 More...

Go to the source code of this file.

Functions

char * strncat (char *s1, const char *s2, int n)
 文字列s1の末尾に文字列s2をN文字(Byte)分、結合する。 More...
 

Detailed Description

文字列s1の末尾に文字列s2をN文字(Byte)分、結合する。

Definition in file strncat.c.

Function Documentation

◆ strncat()

char* strncat ( char *  s1,
const char *  s2,
int  n 
)

文字列s1の末尾に文字列s2をN文字(Byte)分、結合する。

処理の流れは、以下の通り。
Step1. 文字列s1のNULL終端'\0'までポインタを進める。
Step2. 文字列s1のNULL終端の位置から文字列s2を一文字ずつ連結する。
Step3. N+1回目にNULL終端を付与する。

Parameters
[in,out]s1結合先の文字列
[in]s2結合する文字列
[in]n結合する文字数(Byte)
Returns
結合後の文字列s1を返す(NULL終端済み)。

Definition at line 17 of file strncat.c.

18 {
19  char *os1;
20 
21  os1 = s1;
22  while (*s1++)
23  ;
24  --s1;
25  while ((*s1++ = *s2++))
26  if (--n < 0)
27  {
28  *--s1 = '\0';
29  break;
30  }
31  return (os1);
32 }