Str_Cat()
Concatenates a string to the end of another string.
Files
lib_str.h/lib_str.c
Prototype
CPU_CHAR *Str_Cat ( CPU_CHAR *pstr_dest, const CPU_CHAR *pstr_cat);
Arguments
pstr_dest
Pointer to the string memory buffer to append string characters into.
pstr_cat
Pointer to the string to concatenate onto the destination string.
Returned Value
Pointer to concatenated destination string, if no errors;
Pointer to NULL
, otherwise.
Required Configuration
None.
Notes / Warnings
Destination buffer size (pstr_dest
) is not validated; buffer overruns must be prevented by caller. IEEE Std 1003.1, 2004 Edition, Section ‘strcat()
: DESCRIPTION’ states that “the initial byte of [pstr_cat
] overwrites the null byte at the end of [pstr_dest
]” and a “terminating null byte” is appended “to the end of the string pointed to by [pstr_dest
]”. Therefore, the destination buffer size must be large enough to accomodate the original destination string size plus the entire concatenated string size, but including only a single terminating NULL
character.
String concatenation terminates if either string pointer points to or overlaps the NULL
address.
Example Usage
CPU_CHAR AppBuf[30]; CPU_CHAR *pstr; pstr = Str_Copy(&AppBuf[0], "Hello World!"); if (pstr != (CPU_CHAR *)0) { pstr = Str_Cat(&AppBuf[0], "Goodbye World!"); } if (pstr == (CPU_CHAR *)0) { printf("STRING COPY/CONCATENATION FAILED!"); }