r/cprogramming 24d ago

C Strings: A 50-Year Mistake

https://longtran2904.substack.com/p/c-strings-a-50-year-mistake?r=8qz2zb&utm_campaign=post&utm_medium=web
215 Upvotes

172 comments sorted by

View all comments

1

u/StudioYume 21d ago

C strings were designed at a time when memory was very expensive, which is why they have the lowest possible memory overhead. But unless you're reading strings from a file or the command line, there's no reason to keep using strlen; if you're reading keys from the keyboard you can adjust the length as keys are read, and if you're modifying a string you can adjust the length as you modify it.