Update
Only logged in members can reply and interact with the post.
Join SimilarWorlds for FREE »

It's updated for today's commit.

https://github.com/kythrasuntamer/Secure-Fahrenheit.-to-Celsius-conversion-in-C

The code is getting better and better

lines (18 sloc) 538 Bytes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "float-input.h"

int main() {
float fahr, celsius;

puts("Enter temperature in Fahrenheit: ");
getFloatFromStdin(&fahr);

while (isnan(fahr) || isinf(fahr)) {
fprintf(stderr, "[ERROR]: Invalid input: please enter a valid temperature.\n");
puts("Enter temperature in Fahrenheit: ");
getFloatFromStdin(&fahr);
}

celsius = (fahr- 32) * 5 / 9;

printf("%3.0f %6.10f\n", fahr, celsius);

return 0;
}


cl.exe /nologo /Ox /MT /W0 /GS- /DNDEBUG /I "path to the .h file" faherheit_to_celsius.c /link /OUT:faherheit_to_celsius.exe /SUBSYSTEM:CONSOLE /MACHINE:x64
This page is a permanent link to the reply below and its nested replies. See all post replies »
Author unknown:




When I find my code in tons of trouble
Friends and colleagues come to me
Speaking words of wisdom
Write in C

As the deadline fast approaches
And bugs are all I can see
Somewhere someone whispers
Write in C

Write in C
Write in C
Write in C
Write in C
LISP is dead and buried
Write in C

I used to write a lot of FORTRAN
For science it worked flawlessly
Try using it for graphics
Write in C

If you just spent nearly 30 hours
Debugging some assembly
Soon you'll be glad to
Write in C

Write in C
Write in C
Write in C, yeah
Write in C

Only wimps use BASIC
Write in C

Ever more at https://genius.com/Unattributed-write-in-c-lyrics
DeWayfarer · 61-69, M
@ElwoodBlues I have issues with C though. Too bloated.

C is to assembly as COBOL is to C.
@DeWayfarer Most of what I do in C would take 10 or 50X longer to code in assembler. And I don't think I'm as smart about optimizing as the compiler is; I don't know when it's better to unroll loops or to vectorize my numerical codes. And then there's memory management; pointers to dead memory are already too easy in C; nightmare in assembly.
DeWayfarer · 61-69, M
@ElwoodBlues it's been decades since I programed, yet my TSRs where far smaller and faster then the C versions.

When you really get into the timing of assembly instructions you can take advantage of those little nuances.

Yes, it takes a lot of work. I never was afraid of any kind of work though.
@DeWayfarer I wrote a medium sized project in Z80 assembler back in the day. I had to do everything; de-bounce button presses; control 7-segment digits, and calculations to several decimal places. For the math, I ended up building 128 bit fixed-point routines; 64 bits of fraction plus 64 bits of int. Division by shift and subtract, convert to decimal by repeated division & subtraction; the whole 9 yards.

These days memory is far cheaper than developer time; write in C with a tool like Purify to catch your pointer errors.
DeWayfarer · 61-69, M
@ElwoodBlues true about the time. True about the bloat though. You are trading one for the other.

There simply is far too much bloat in today's code. We are quickly approaching the heat limits when it comes to todays computers.

Time to eliminate the bloat.
@DeWayfarer Data point: this guy wrote X86 code for a matrix determinant in both C++ and ASM. In his case, the C++ was faster by about 6%.

https://www.codeproject.com/Articles/1182676/Need-for-Speed-Cplusplus-versus-Assembly-Language
DeWayfarer · 61-69, M
@ElwoodBlues that is dependent on the programmers techniques. I think you know that.