Quantcast
Viewing latest article 27
Browse Latest Browse All 42

Answer by Lundin for Circle & Sphere Calculator

  • 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 call tolower on every character. Then you can use standard strcmp 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. The strto... functions are equivalent, except they also have error handling. In this case, replace atof with strtod(str,NULL).

Viewing latest article 27
Browse Latest Browse All 42

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>