C has no string type. A "string" is an array of char ending in a null terminator, the byte '\0'. Every library function finds the end by scanning for that byte, which has three consequences: strlen is O(n) rather than a stored length, a string needs n + 1 bytes to hold n characters, and a buffer whose terminator is missing or overwritten will be read until one happens to appear somewhere in memory.
char *s = "hello" and char s[] = "hello" are different in a way that matters. The first points at a string literal, which lives in read-only memory - writing through it is undefined behaviour and usually a segmentation fault. The second copies those bytes into a local array you own and may modify. Declare literals as const char * so the compiler enforces it.
The <string.h> functions divide into the dangerous and the careful. strcpy and strcat write until they hit a terminator with no regard for the destination's size, and are the classic buffer overflow. strncpy and strncat take a limit - but strncpy has a trap of its own: if the source is exactly as long as the limit it does not write a terminator, so the result is not a string. snprintf is usually the better tool, because it always terminates and tells you how much it wanted to write.
strcmp returns zero when the strings are equal, which is the opposite of what if (strcmp(a, b)) reads like.
#include <stdio.h>
#include <string.h>
int main(void)
{
/* Read-only memory. Writing through this is undefined behaviour,
and usually a segmentation fault. const makes that a compile error. */
const char *literal = "hello";
/* A copy you own, in your frame, and may modify. Six bytes for five
characters: the terminator needs one. */
char mutable_copy[] = "hello";
mutable_copy[0] = 'H';
printf("%s %s\n", literal, mutable_copy);
printf("strlen %zu, sizeof %zu\n",
strlen(mutable_copy), sizeof mutable_copy); /* 5 and 6 */
char dest[16];
/* strcpy writes until it finds a terminator in the SOURCE and does
not know how big dest is. This is the classic overflow. */
/* strcpy(dest, "a string far longer than sixteen bytes"); */
/* snprintf always terminates, and returns how much it WANTED to
write - so a value >= the size means it was truncated. */
int wanted = snprintf(dest, sizeof dest, "%s-%d", "id", 42);
if (wanted >= (int) sizeof dest) printf("truncated\n");
/* strncpy's trap: if the source is exactly n long it writes NO
terminator, and the result is not a string. */
char fixed[6];
strncpy(fixed, "abcdef", sizeof fixed);
fixed[sizeof fixed - 1] = '\0'; /* always do this after */
/* strcmp returns 0 when they are EQUAL, which reads backwards. */
if (strcmp(dest, "id-42") == 0) printf("match\n");
printf("%s | %s\n", dest, fixed);
return 0;
}