Reputation: 9
This is for my into to C class, and I can't figure out why I'm getting this error:
while (scanf ("%d", (int)ph[i].vi.temperature) < 0) {
warning: format '%d' expects argument of type 'int *', but argument 2 has type 'int'
Code:
struct vitalInformation {
float temperature;
unsigned int systolicPressure;
unsigned int diastolicPressure;
};
struct activityInformation {
unsigned int stepCount;
unsigned int sleepHours;
};
union patientHealth{
struct vitalInformation vi;
struct activityInformation ai;
} ph[100];
int i = 0;
int menu(){
int option;
printf ("Please enter the number for the desired action (1, 2, 3):\n");
printf ("1 - Enter some patient vital information\n");
printf ("2 - Enter some patient activity information\n");
printf ("3 - Print summary information on the patient information and exit the program\n");
scanf ("%d", &option);
while (scanf("%d", &option) || option<1 || option>3) {
printf ("Please enter 1, 2, or 3\n\n");
printf ("Please enter the number for the desired action (1, 2, 3):\n");
printf ("1 - Enter some patient vital information\n");
printf ("2 - Enter some patient activity information\n)");
printf ("3 - Print summary information on the patient information and exit the program\n");
fflush (stdin);
scanf ("%d", &option);
}
return option;
}
void patientVitalInfo(int *countP, float *minT, float *maxT, int *minS, int *maxS, int *minD, int *maxD) {
printf ("Enter the temperature: ");
scanf ("%f", &ph[i].vi.temperature);
while (scanf ("%d", (int)ph[i].vi.temperature) < 0) {
printf ("Please enter an integral unsigned number\n");
printf ("Enter the temperature: ");
fflush (stdin);
scanf ("%f", &ph[i].vi.temperature);
}
}
Upvotes: 0
Views: 6527
Reputation: 15641
The error reported comes from your line
while (scanf ("%d", (int)ph[i].vi.temperature) < 0) {
which is casting whatever you get form ph[i].vi.temperature
(in this case, a float
) into an int
, while scanf
requires a pointer to an int
.
Now, in your case, you seem to need the temperature as an int
, while
ph[i].vi.temperature
holds a float
, so you would rather use another int
variable, say
int itemp;
scanf ("%d", &itemp);
for the input and then
ph[i].vi.temperature = (float) itemp;
for the casting.
Or, you could simply scanf ("%f", &ph[i].vi.temperature);
and then keep the integral part.
I wouldn't know your needs nor the logic behind your code.
Note: I am not sure you are using the return value of scanf
in a way matching your needs either.
In your case, scanf
can return 0
, 1
or EOF
.
Upvotes: 2