hi all,
i'm learning C at the moment, and one of the programs given as example converts fahrenheit to celsius.
But since i like to reverse the program, to convert celsius to fahrenheit, i've rewritten it to learn from it.
only problem is, when i run it and enter a value for celsius, i get an segmentation fault.
what did i do wrong? here is the source:
i've tried changing the var fahr to a double, and even an int, but the same problem still persists..Quote:
#include <stdio.h>
main()
{
int celsius;
float fahr;
printf("This is very a simple program which allows\n");
printf("you to convert a celsius value to fahrenheit.\n");
printf("\nType the value of celsius you want converted:\n");
scanf("%3d", celsius);
fahr = celsius / (5.0/9.0) + 32;
printf("%3d degrees celsius is %3.2f degrees fahrenheit.", celsius, fahr);
return 0;
}
and when i do the calculation with a scientific calculator the result is correct.
