StringCopyMax
void StringCopyMax (char destination[], const char source[], size_t destinationBufferSize);
Purpose
Copies the string pointed to by source to the array of characters pointed to by destination. No more than the number of characters specified by destinationBufferSize will be copied (including the nul byte).
This function is similar to the C Library strncpy function, except StringCopyMax has the following three advantages:
- If the source string is larger than the destination buffer size, then as much of the source string as possible will be copied with the provision that the last byte in the destination buffer will be a nul string terminator. strncpy DOES NOT nul terminate the copied string when the source string is too long.
- StringCopyMax does not write into the destination string past the point necessary to copy the string. strncpy fills the end of the destination array with zeros, up to the specified buffer size.
- StringCopyMax is tolerant of overlaps between the source and destination strings. strncpy is not.
Parameters
Input | ||
Name | Type | Description |
source | const char[] | Contains a pointer to the null–terminated source string that will be copied to the destination string subject to the length limit imposed by destinationBufferSize. |
destinationBufferSize | size_t | Pass the size of the destination buffer (including space for the nul byte). StringCopyMax will copy no more than the specified number of bytes (including the nul byte) regardless of the length of the source string. |
Output | ||
Name | Type | Description |
destination | char [] | Contains the target string to which the source string will be copied. |
Return Value
None.
Additional Information
Library: Programmer's Toolbox
Include file: toolbox\toolbox.h
LabWindows/CVI compatibility: LabWindows/CVI 4.0 and later