- It's bad practice to use non-standard functions needlessly. Instead of calling non-standard
_stricmp
all over the place, you can just iterate over the input string once and calltolower
on every character. Then you can use standardstrcmp
instead. This should also improve performance ever so slightly. - Calling
strcmp
repeatedly 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
\n
inside 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, replaceatof
withstrtod(str,NULL)
.
↧
Answer by Lundin for Circle & Sphere Calculator
↧