Logan Stafford
Logan Stafford

Reputation: 1

C Language: Functions and "Format Type" Error

I'm trying to make a program with three functions, one that takes the input (p,v,t) from a file, a second that calculates m, and a third to output the four variables (p,v,t,m). The following is my code. I'm using xCode, and found no errors besides one on line in my second function ("if(fscanf(inptr, "%d %d %d", p, v, t) !=EOF)"). The error is "Format specifies type 'int *' but the argument has type 'float *" I'm not quite sure what I'm doing wrong.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int funcinput (float *, float *, float *);

int main ()
{
    float p, v, t;
    int flag;
    flag = funcinput (&p, &v, &t);
    if(flag)
        printf("var1 = %f var2 = %f var3 = %f\n", p, v, t);
    else
        printf("Error in input.\n");

    return 0;

}

int funcinput (float *p, float *v, float *t)
{
    int flag = 0;
    FILE *inptr;

    inptr = fopen("datex.dat", "r");
    if(fscanf(inptr, "%d %d %d", p, v, t) !=EOF)
        flag = 1;

    return flag;
}

int calculatem (float p, float v, float t, float o)
{
    float m = 0;
    o = p * v;
    o = (0.42 * m) * (t + 460);
    m = (p * v) / (0.42 * (t + 460));
    return m;
}

    void funcans (float p, float v, float t, float m)
{
    printf ("The mass of a balloon inflated to %5.2f cu ft, at %5.2f psi, at %5.2f     degrees is %5.2f.\n", v, p, t, m);

    }

Upvotes: 0

Views: 161

Answers (1)

user376507
user376507

Reputation: 2066

Your arguments p, v, t are pointers to floating point variables. You should be using %f to read into them.

Upvotes: 3

Related Questions