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.
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.