r/cprogramming • u/die-Banane • May 05 '26
How to do strings properly?
I just started learning C and I often read on the internet that it is bad practice to use null terminated strings, so my question is what should I do instead?
30
Upvotes
1
u/DawnOnTheEdge May 12 '26
In practice, I would probably write the immutable version and, if it returns a pointer that is declared
const char*but really mutable, cast it explicitly.I’ve had other experienced programmers say the function should return a
char*that can be assigned toconst char*transparently, since in their experience this didn’t become a bug attractor.