Although I understand the layout of this program is wierd, I think my program is having trouble when it comes to the scanf()
line. For some reason after the metricConversion()
function is entered. The scanf()
line is printed but the program exits and terminates before an input is given... I am not understanding why this happens...
#include <stdio.h>
char inputtedChar;
int inputtedInt;
int metricConversion(){
scanf("Press K for conversion from Kelvin to Celsius %c", &inputtedChar);
if(inputtedChar == 'K'){
//do Something
} else { return 0; }
}
int main() {
printf("Press 0 to enter conversion function!");
scanf("%d", &inputtedInt);
if (inputtedInt == 0) {
metricConversion();
}
}
More importantly, can someone explains why scanf()
works the way it does? And what the best alternatives are so I dont run into this again?