Next Previous Contents

3.156 strncpy

Function

Copy part of a string.

Header

string.h

Declaration

char* __fastcall__ strcpy (char* s1, const char* s2, size_t n);

Description

The strncpy function copies not more than n bytes from the array pointed to by s2 to the array pointed to by s1. If the array pointed to by s2 is a string that is shorter than n bytes, null bytes are appended to the copy in the array pointed to by s1, until n bytes are written. The function will always return s1.

Limits

  • The function is only available as fastcall function, so it may only be used in presence of a prototype. If there is no null byte in the first n bytes of the array pointed to by s2, the result is not null-terminated.
  • If copying takes place between objects that overlap, the behaviour is undefined.

Availability

ISO 9899

See also

strcat, strcpy, strncat

Example

#include <string.h>

static char hello[6];

strcpy (hello, "Hello world!\n", sizeof (hello) - 1);
hello[5] = '\0';


Next Previous Contents