On this page
strcat
Prev: strcpy | Up: string.h | Next: strncpy
Rel: snprintf(), string.h, stdlib.h & string.h Guide
Ref: cppreference — strcat
Tags: #public #prog #c #stdlib #string #tier/legacy
Include
#include <string.h>
Signature & Overview
char *strcat(char *restrict dst, const char *restrict src);
Unbounded string concatenation with $O(n)$ repeated scanning.
Legacy / Avoid: Prefer snprintf() in all new code.
Notes & Pitfalls
- Unbounded & $O(n)$ scan for the end: Avoid
strcat()—track current length and usesnprintf()ormemcpy().
Example
#include <assert.h>
#include <stdio.h>
#include <string.h>
int main(void) {
char buf[16];
snprintf(buf, sizeof(buf), "%s%s", "hello ", "c");
assert(strcmp(buf, "hello c") == 0);
}
Linked from
Related notes
- tuts/c/stdlib/string/strcpy Linked here; links to this page; shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/strncpy Linked here; links to this page; shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string Linked here; links to this page; shared tags: #c, #prog, #stdlib, #string
- tuts/c/stdlib/stdio/snprintf Linked here; shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/stdlib_and_string_h Linked here; shared tags: #c, #prog, #stdlib
- tuts/c/stdlib/string/memchr shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/memcmp shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/memcpy shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/memmove shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/memset shared tags: #c, #prog, #stdlib, #string, #tier