strncat()

Appends up to a maximum of a specified number of characters to a character array.

  #include <string.h>
  
  char *strncat(char *dest, const char *source, size_t n);    
Parameter

dest

A pointer to a character to append to.

source

A pointer to the character string to append to dest.

n

The maximum number of characters to append from source.

Remarks

This function appends up to a maximum of n characters from the character array pointed to by source and an extra null character ('\0'). to the character array pointed to by dest. The dest argument must point to a null-terminated character array. The source argument does not necessarily have to point to a null-terminated character array.

If the function encounters a null character in source before n characters have been appended, the function appends a null character to dest and stops.

The function returns the value of dest.

This facility may not be available on some configurations of the EWL.

Listing: Example of strncat() Usage

#include <string.h>

#include <stdio.h>

int main(void)

{

char s1[100] = "abcdefghijklmnopqrstuv";

char s2[] = "wxyz0123456789";

strncat(s1, s2, 4);

puts(s1);

return 0;

}

Output:

abcdefghijklmnopqrstuvwxyz