Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ strncpy(3) — CLIX 3.1r7.6.22

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

index(3)

rindex(3)

strcat(3)

strcmp(3)

strcspn(3)

strchr(3)

strcpy(3)

strlen(3)

strncat(3)

strncmp(3)

strpbrk(3)

strrchr(3)

strspn(3)



  strncpy(3)                          CLIX                          strncpy(3)



  NAME

    strncpy - Copies a specified number of bytes from one string onto another

  LIBRARY

    Standard C Library (libc.a)

  SYNOPSIS

    #include <string.h>

    char *strncpy(
      char * string1 ,
      char * string2 ,
      size_t number );

  PARAMETERS

    string1
           A pointer to a character string

    string2
           A pointer to a character string

    number The number of bytes to copy

  DESCRIPTION

    The strncpy() function copies no more than the number of characters
    specified by the number parameter from the location pointed to by the
    string2 parameter to the location pointed to by the string1 parameter.
    Characters following a null character are not copied.  When operating on
    overlapping strings, the behavior of this function is unreliable.  When
    the location pointed to by the string2 parameter is a string whose
    character length is less than the value specified by the number parameter,
    null characters are appended to the string1 string until number characters
    are contained in the string.

  EXAMPLES

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

    main()
    {
       char string1[20];
       char *string2 = "hello world!";

       /* copy the first 5 characters of "hello world!" into string1 */
       strncpy (string1, string2, 5);



  2/94 - Intergraph Corporation                                              1






  strncpy(3)                          CLIX                          strncpy(3)



      /* since 5 is less than the length of string2, a null character must be added */
      string1[5] = `\0';

      printf ("The first 5 characters of string '%s' are '%s'\n",
           string2, string1);
    }


  RELATED INFORMATION

    Functions: index(3), rindex(3), strcat(3), strcmp(3), strcspn(3),
    strchr(3), strcpy(3), strlen(3), strncat(3), strncmp(3), strpbrk(3),
    strrchr(3), strspn(3)









































  2                                              Intergraph Corporation - 2/94




Typewritten Software • bear@typewritten.org • Edmonds, WA 98026