I am brand new to programming in C. I am following along with the book "The C Programming Language, Second Edition." I am making my own modifications to the example code presented in the book as I go along. Anyway I am posting my code here for review because I want to make sure I am off to a good start. There a few things in particular that I want to make sure that I am doing right as to not develop any future bad habits:
I would like to make sure I am adhering to the C standards. Based on my research I found that the current and most recent standard for C is C17 or ISO/IEC 9899:2018, please correct me if I am wrong. As a result I have been compiling the code with the following parameters:
gcc -Wall -pedantic-errors -std=c17 source.c
Is this a good practice?I know I am a beginner but I would like to make sure that I am doing even the simplest things in a clean and efficient way.
So if I can get a review on this code sample, that would be great.
/* This program uses the formula C = (5/9)(F-32) to print a table of Farenheit
* temperatures and their Centigrade or Celsius equivalents. Adapted from:
* Kernighan, B. W., & Ritchie, D. M. (1988). The C programming language. */
#include <stdio.h>
/* Print Fahrenheit-Celsius table for Fahrenheit = 0, 20, ..., 300. */
int main(void)
{
float fahr, celsius;
int lower, upper, step;
lower = 0; /* Lower limit of temperature table. */
upper = 300; /* Upper limit. */
step = 20; /* Step size. */
printf("Fahrenheit to Celsius\n"); /* Table header */
printf("%3s %6s\n", "F", "C"); /* Temperature label */
fahr = lower;
while (fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
printf("%3.0f %6.1f\n", fahr, celsius);
fahr = fahr + step;
}
}