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 »
C is seems cumbersome
PDXNative1986 · 36-40, MVIP
@TheDeathOfOzymandiaz That's the price for small file sizes and speed. even if it would be easier in another language it'll perform better in C. optimized.
@PDXNative1986 YOu tried any Python?
PDXNative1986 · 36-40, MVIP
@TheDeathOfOzymandiaz Yes. Python's interepter was written in c. it's good at a lot of things. C would still be faster at doing all of those things.
@TheDeathOfOzymandiaz I had a CS teacher who used to say that you only start to understand what programming is when you're on your 2nd or 3rd language.

I'm a might big fan of Python; I think the ideal these days is write some UI and maybe control logic in Python, but do the numerical stuff in C so you can take advantage of the speed & size benefits.
PDXNative1986 · 36-40, MVIP
@TheDeathOfOzymandiaz python is supposed to make developers happy but what makes me happy is code that executes quickly. and while c is "cumbersome" in the kind of way like having to declare your variables and everytihng thats what makes it perform well.

I like python but that isn't going to change the fact that a lower level language can do what python can do and quicker. C isn't assembly sure but it's a hell of a lot faster at developing than assembly. you think c is bad you should look at assembly.

I started learning C because the last thing I want to be is a soydev, who doesn't give a fuck if it performs well because computers will get faster in the future.