Loading…
Loading…
Topic
Articles and problems tagged Strings.
Write string functions yourself: find a character, find a substring, sort names, compress repeated spaces and encode a message. Each exercise has a hint and a full, runnable solution.
Short questions on strcat with literals, defining your own strcpy, and processing strings, followed by output puzzles that combine pointers, strcmp, strcat and 3-D char arrays.
Puzzles with pointers walking through strings: printing backwards, two pointers meeting in the middle, one-line string copy, three levels of pointers, and arrays of strings.
Worked puzzles on strings: the '\0' terminator, adding numbers to string literals, comparing strings with ==, sizeof on arrays of pointers and more. Predict the output, then check the explanation.
Store a list of strings as a 2-D char array or as an array of pointers. Compare memory use on 64-bit systems, swapping strings, and reading strings in with malloc, with clear diagrams.
char arrays vs pointers to string literals: what can be assigned, what can be changed, and why modifying a literal crashes. Then master const, including const char *, char *const and returning const.
Learn strlen, strcpy, strcat and strcmp from <string.h>, then write each one yourself with pointers. Includes buffer overflow pitfalls, why strcmp only guarantees a sign, and safer snprintf.
A C string is a char array ending in '\0'. Learn why the terminator matters, how to walk a string with indexes and pointers, and how to print and read strings safely with %s, scanf and fgets.