3 ms·
The fact that C strings are presented in this format is totally irrelevant for the discussion of string search algorithms. They all have to know the length. Str
by OskarS 5y ago
The fact that C strings are presented in this format is totally irrelevant for the discussion of string search algorithms. They all have to know the length. Strings in most languages are not in that format, and it is an entirely reasonable assumption that the length is a known quantity.
If you wanna be annoying about this, just imagine he's implementing `strnstr` instead of `strstr`.
- delusional 5y agoTo me it looks like you could quite easily convert this strstr function to look for 0 bytes. You don't even need to know the length up front. It's just used to make some of the loop bounds more clear.