[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
strncpy()                Copy a Specified Number of Characters

 #include   <string.h>                   Required for declarations only

 char         *strncpy(string1,string2,n);
 char         *string1;                  Destination string
 char         *string2;                  Source string
 unsigned int  n;                        Number of characters copied

    strncpy() copies exactly 'n' characters from 'string2' to 'string1'.
    The terminating null character ('\0') is not automatically appended
    if 'n' is less than the length of 'string2'.  If 'n' is greater than
    the length of 'string2', 'string1' is padded with null characters
    after the copy, up to the length 'n'.

    Returns:    A pointer to the copied string.

  -------------------------------- Example ---------------------------------

    The following statements copy 'n' characters of string2 to string1
    and print out the result.

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

         char *copy;
         char string1[50];
         char string2[25] = "reference guide";

         main()
         {
             copy = strncpy(string1,string2,10);
             printf("%s\n",copy);
         }

See Also: strcpy()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson