File Handling Calculation In C : <p>I want to calculate body mass index and write it to the file.I've tried to calculate it in a another function as you can see but output is just 0.Then I've tried different functions like int calculate returns to w/h*h but none of them give me the right answers.I couldn't find another way.</p>

<pre><code>#include &lt;stdio.h&gt;
struct person
{
    int personId;
    double height;
    double weight;
    double BMI;
}; 

void calculate (double h, double w)
{
    struct person p1;
    p1.BMI = w / h*h ;
}
void write () {
FILE *file;
struct person p1;
file = fopen("bmi.txt","w");
if (file == NULL)
{
    printf("Error");
}
else
{
    printf("Person ID: "); scanf("%d",&amp;p1.personId);
    printf("Height: "); scanf("%lf",&amp;p1.height);
    printf("Weight: "); scanf("%lf",&amp;p1.weight);
    calculate(p1.height,p1.weight);
    fwrite(&amp;p1,sizeof(p1),1,file);

 }
fclose(file);
}

void read() {
FILE *file;
struct person p1;
file = fopen("bmi.txt","r");
if (file == NULL)
{
    printf("Error");
}
else
{
    while (!feof(file))
    {
        fread(&amp;p1,sizeof(p1),1,file);
        printf("Person ID: %d\n",p1.personId);
        printf("Height: %f\n",p1.height);
        printf("Weight: %f\n",p1.weight);
        printf ("BMI: %f\n",p1.BMI);
    }
}
fclose(file);
}

int main () {
write();
read();
}
</code></pre>
