4 ms·
What if there is no null?
by ChrisSD 8y ago
What if there is no null?
- a1369209993 8y agoIf there isn't a NUL, then you're asking for a property relevantly distict from length of a datum relevantly distinct from a C-string. Use `strchr(s,0x00)` or `memchr(s,0x00,zs)`.
- deleted 8y ago[deleted]
- slrz 8y agoThen you probably shouldn't feed it to the str* functions at all. Use the mem* functions instead.
- ChrisSD 8y agoThat's the same as saying you should never use the str* functions. Nothing in C guarantees a string must have a null byte. As you're well aware, C-strings aren't a separate type that's distinct from char arrays. Sure you can say that good programmers will always ensure a C-string is a C-string but there's decades of programming history that shows that's not true in practice.
- saagarjha 8y agoThen use a language other than C that doesn't shoehorn string handling into char , as I've mentioned in other comments. If you're have a char with no terminating null byte and you hand it to a function with "str" and its name, you're going to have a bad time.