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?
32
Upvotes
View all comments
Show parent comment
1
u/flatfinger May 11 '26
Sometimes a function will accept a pointer to storage that may or may not be mutable, and return a storage which is based on the original. Such a function should be usable both in cases where the passed-in pointer addresses mutable storage, or where the return value will not be used to mutate the storage identified thereby, without need to distinguish between the two usage patterns, but C makes that awkward.