3 ms·
My observations, as an opinionated C programmer: 1. Missing const; always const all the things, especially pointers passed to functions. Semantically a "find"
by unwind 5y ago
My observations, as an opinionated C programmer:
1. Missing const; always const all the things, especially pointers passed to functions. Semantically a "find" would be a read-only operation, to me it's a huge red flag if it's not const-declared.
2. Why NULL-check the array but not the name? I guess it doesn't affect functionality, or perhaps NULL is a valid name. Confusing without more context/commentary.
3. I prefer "++i" rather than "i++" in for loops like this because of reasons, but that's a rather minor point of course.
4. Be daring and use at least C99, move the "int i" to the for-loop's initializing part.
5. It's not obvious that the comparison doesn't need strcmp(), but might be clear from context, would expect comment to clarify that.
I agree with the top-down rewrite and find the revised code better, it's just not ... good enough yet. :)
Edit: list formatting.