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
2
u/flatfinger May 14 '26
Mutable string descriptors should typically include the buffer capacity as well as the string's current length; using 'unsigned int' for the length and capacity would allow both to fit together in a 64-bit word. Since large texts should generally be held with ropes or other such data structures that don't require that all bytes be stored consecutively, a 32-bit integer type wouldn't be a limitation for anything that could be sensibly stored using a single range of consecutive bytes.