C a Day 1: Farenheight to Celsius Conversion Table

C a Day 1: Farenheight to Celsius Conversion Table

Following along with "The C Programming Language" by Dennis Ritchie and Brian Kernighan, each day I will attempt to write a C program. Sometimes useful, sometimes...well.  To begin, an example from the first chapter of the aformentioned book, conversion from farenheight to celsius.

C is making a comeback, and its not just my opinion anymore. The IEEE spectrum[1] has it at second for 2017 just behind python. I enjoy python for its simpilicty but at times it feels like I am just going through the motions. The documentation is great, and if you have an IDE the code pretty much writes itself. Boring. Give me bare bones speed. A stick shift with an engine that makes the hair on my neck stand up. For that I need C.

Since it is just day one, lets write a program that you would handle in a typical introductory computer science course at a university; printing a table of farenheight to celsius conversion.

Include the standard input/ouput library with #include "stdio.h".

Lets then define some constants we will use in this program (I KNOW right, C has constants too!),

#define LOWER 0;
#define UPPER 100;
#define STEP 5;

Alas the main function. The function that serves as the entry point for every C program. A function with a special place in the heart of C programmers, blah blah blah.

Note that if you are following along in the 2nd edition of the book mentioned in the teaser, you need to declare the type of function that main is, and typically this is int[2].

   1 #include "stdio.h"
  3 #define LOWER 0     /* Lower limit of conversion */
  4 #define UPPER 200   /* Upper limit of conversion */
  5 #define STEP 20     /* Step size to get there */
  7 int main() {
  8     float f, c;
  9     int lower, upper, step;
 11     printf("==============================\n");
 12     printf("%6s %6s\n", "Faren", "Celsius");
 13     printf("==============================\n");
 15     for (f = LOWER; f