Other than the strcmp
problem which has been addressed in an other answer there are three problems in this piece of code:
const char* temp1;
printf("Enter the Temperature in Fahrenheit:
");
scanf("%s",temp1);
- you don't want
const
because the value you want to get from the user is not ... constant
temp1
is an uninitialized pointer that points nowhere
- you don't need a string here but you want the user enter a number
So you want actually something like this:
float tempFahrenheit;
printf("Enter the Temperature in Fahrenheit:
");
scanf("%f", &tempFahrenheit);
float tempCelsius = ... // I let you write the rest of the code yourself
If you want get a string from the user and convert that to a number you might want something like this:
float tempFahrenheit;
char inputstring[20]; // max length of string is 20
printf("Enter the Temperature in Fahrenheit:
");
scanf("%s", inputstring);
sscanf(temp, "%f", &tempFahrenheit);
float tempCelsius = ... // I let you write the rest of the code yourself
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…