Guardian C Library Calls Reference Manual
Reference to Library Calls
Guardian TNS C Library Calls Reference Manual—128833 3-205
strncpy
strncpy
The strncpy function copies not more than a specified number of characters from one
string to another.
str1_ptr
points to the destination string. *str1_ptr must accommodate at least max characters.
str2_ptr
points to the string to copy.
max
specifies the maximum number of characters to copy; max must be a positive
integer.
Return Value
points to the resulting string.
Usage Guidelines
•
If the length of *str2_ptr is less than max, then *str1_ptr is padded to max length
with null characters. If the length of *str2_ptr is greater than max, then *str1_ptr
will not have a terminating null character.
Example
This example prints the first six characters of s1, “Tandem”:
#include <stringh>
#include <stdioh>
int main(void)
{
char s1[10];
char *s2;
char *s3;
s2 = "Tandem Computers Incorporated";
s3 = strncpy(s1,s2,6);
printf("%s",s3); /* "Tandem" */
}
#include <stringh>
char *strncpy(char *str1_ptr, const char *str2_ptr,
size_t max);