Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>strncpy() copy a specified number of characters</b> http://www.X-Hacker.org [<<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
 const char   *string2;                  Source string
 size_t        n;                        Number of characters copied

    strncpy() copies '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, up to the length of 'n',
    with null characters after the copy

    Returns:    A pointer to the copied string.

       Note:    Behavior of strncpy() is undefined if the address ranges
                for 'string1' and 'string2' overlap.

   -------------------------------- 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,20);
               printf("%s\n",copy);
           }


See Also: strcpy()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson