Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo C ) - <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 the specified '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()

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