2 ms·
No, if you want sensible string handling, the sane choice is usually to choose to use a language that is not C. Not always, but definitely usually.
by yxhuvud 6y ago
No, if you want sensible string handling, the sane choice is usually to choose to use a language that is not C. Not always, but definitely usually.
- IgorPartola 6y agoIt’s not hard to have strings like you do in other languages in C. It is hard when you treat char foo[] as if it was a string object like you have in JavaScript or Java or Python. C strings are just chunks of memory terminated by \0. They can still be mildly useful that way but if you actually want to do string operations you need to use a library designed for the problem (variable length, storing length with the object, Unicode support, etc.). Problem is that most people don’t start with such a library so they end up doing the hard work themselves in an ad hoc manner. You can’t fuck up String(“Hello “) + String(“world”) but you can definitely fuck up strcat(buf, “Hello “); strcat(buf, “world”);.