r/cprogramming • u/Creative-Copy-1229 • Feb 18 '26
Could you review my code
Hello everyone. I am a beginner in C. I wrote a calculator that's slightly more useful than simple "input number one, operation, number two". It accepts simple arithmetic expressions. Please can you review the code and tell me is it really bad, and what I should improve. A person said this code is bad even for beginner level, that it's a mess, so I decided I would like to see other opinions
4
Upvotes
View all comments
Show parent comment
1
u/simmepi Feb 19 '26
Yep, outputting error is also a good way to handle it, and I’ve sometimes used it as well. The most depressing situation was one where I was working with cross platform C code and among the compilers were Microsoft’s and Sun’s, and I had a switch case for an enum. So using the pattern I described, ie no default, everything was fine on Solaris. However, MS reported the missing default as a warning and you couldn’t configure the flags to make it ignore it. So I added a default to get rid of the warning → the Solaris compiler now complained about an unnecessary default (it was smart and realized I had explicitly handled all the values in the enum and hence the default was unreachable code). This was also not possible to configure so as to silence the warning…