main.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. Ye olde temperature converter that would've helped you not flunk that high
  3. school physics class back in the day. Also some good practice for C.
  4. Copyright 2022 - kzimmermann <https://tilde.town/~kzimmermann>
  5. This program is Free Software licensed under the GNU General Public License
  6. v3. See <https://www.gnu.org/licenses> for more information.
  7. */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include "converter.h"
  11. /**
  12. This bit is some documentation for Doxygen. Here's how to use this program:
  13. tempconv OP INPUT_TEMP
  14. Where OP is either one of:
  15. cf - Celsius to Fahrenheit
  16. fc - Fahrenheit to Celsius
  17. ck - Celsius to Kelvin
  18. kc - Kelvin to Celsius
  19. INPUT_TEMP will be cast to float regardless of operation.
  20. */
  21. int
  22. main(int argc, char* argv[])
  23. {
  24. float input;
  25. if (argc == 1) {
  26. input = 26.0;
  27. }
  28. else {
  29. input = atof(argv[1]);
  30. }
  31. printf("%.2f Celsius is %.2f Fahrenheit\n", input, ctof(input));
  32. printf("%.2f Fahrenheit is %.2f Celsius\n", input, ftoc(input));
  33. printf("%.2f Fahrenheit is %.2f Kelvin\n", input, ftok(input));
  34. printf("%.2f Kelvin is %.2f Fahrenheit\n", input, ktof(input));
  35. return 0;
  36. }