From 41a934985a4b4ab38c00d41cda28f8ddbfb20b8b Mon Sep 17 00:00:00 2001 From: Jack-Benny Persson Date: Sun, 13 Sep 2020 00:17:12 +0200 Subject: [PATCH] More refactoring --- Makefile | 2 +- subnetcalc.c | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 6e1816b..8451c83 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ subnetcalc: subnetcalc.c - gcc -Wall -pedantic subnetcalc.c -lm -o subnetcalc + gcc -std=c99 -Wall -pedantic subnetcalc.c -lm -o subnetcalc clean: subnetcalc rm subnetcalc diff --git a/subnetcalc.c b/subnetcalc.c index 68135c9..61623cc 100644 --- a/subnetcalc.c +++ b/subnetcalc.c @@ -9,26 +9,26 @@ int main(void) { int net; - double hosts; - double addr; + long int hosts, addr; printf("Enter netmask in slash-notation without the slash: "); scanf("%2d", &net); - if (net >= 0 && net <= 32) // Sanity check the user input + if (net >= 0 && net <= 32) /* Sanity check the user input */ { printf("Netmask bit: %d\n\n", net); - addr = pow(2, 32-net); // Calculate number of addresses - printf("%.0lf total addresses\n", addr); + addr = pow(2, 32-net); /* Calculate number of addresses */ + printf("%ld total addresses\n", addr); - hosts = addr-2; - if (hosts < 0) // Check if number of usable hosts is a negative value + hosts = addr-2; + /* Check if number of usable hosts is a negative value */ + if (hosts < 0) { - hosts = 0; // Set usable hosts to zero if it was negative + hosts = 0; /* Set usable hosts to zero if it was negative */ } - printf("%.0lf usable addresses for hosts\n", hosts); + printf("%ld usable addresses for hosts\n", hosts); return 0; } - else // If the user entered anything else than 0-32 + else /* If the user entered anything else than 0-32 */ { printf("Only values between 0-32 are accepted\n"); return 1;