- It's bad practice to use non-standard functions needlessly. Instead of calling non-standard
_stricmpall over the place, you can just iterate over the input string once and calltoloweron every character. Then you can use standardstrcmpinstead. This should also improve performance ever so slightly. - Calling
strcmprepeatedly like this is ok for a beginner-level program, but in a real program it is inefficient. For larger data in professional programs, you'd rather use a sorted table and binary search through it, or for very large data use a hash table. - Rather than comparing strings with a
\ninside them, sanitize the input so that it doesn't contain any unwanted characters like that. Removing trailing newline character from fgets() input - There is no reason to declare all your variables outside main() - doing so is generally bad practice, though in case of single file projects it doesn't matter much.
- Never use the
ato...functions. Thestrto...functions are equivalent, except they also have error handling. In this case, replaceatofwithstrtod(str,NULL).
↧
Answer by Lundin for Circle & Sphere Calculator
↧