![]() |
| | #1 |
| Registered User Join Date: Feb 2003
Posts: 33
| Help me with a program involving structs and struct pointers? Code: #include<stdio.h>
void printstruct(struct patient *, int);
struct patient
{
char id[8];
int systolic;
int diastolic;
int ldlchol;
int hdlchol;
};
int main(void)
{
int i = 0;
struct patient p[10];
FILE *pat;
if ((pat=fopen("patients.dat", "r")) == NULL)
puts("Error reading file");
else
{
while(!feof(pat))
{
fscanf(pat, "%s %d %d %f %f", p[i].id, &p[i].systolic,
&p[i].diastolic, &p[i].ldlchol, &p[i].hdlchol);
i++;
}
}
fclose(pat);
printstruct(p, i);
return 0;
}
void printstruct(struct patient *patientPtr, int i)
{
int x = 0;
FILE *patrpt;
if ((patrpt=fopen("patient.rpt", "w"))==NULL)
puts("Error writing to file");
else
{
fprintf("%20s", "Patient's Report");
fprintf("%s", "Patient ID Blood Pressure Cholesterol Ratio\n");
for (x = 0; x <= i; x++)
{
fprintf("%8s %3d\\%3d %9f", patientPtr->id, patientPtr->systolic,
patientPtr->diastolic,(patientPtr->ldlchol/patientPtr->hdlchol));
}
}
fclose(patrpt);
}
"patte.c", line 50.13: 1506-280 (W) Function argument assignment between types " struct {...}*" and "unsigned char*" is not allowed. "patte.c", line 51.13: 1506-280 (W) Function argument assignment between types " struct {...}*" and "unsigned char*" is not allowed. "patte.c", line 54.15: 1506-280 (W) Function argument assignment between types " struct {...}*" and "unsigned char*" is not allowed. those are coming from these lines Code: else
{
fprintf("%20s", "Patient's Report");
fprintf("%s", "Patient ID Blood Pressure Cholesterol Ratio\n");
for (x = 0; x <= i; x++)
{
fprintf("%8s %3d\\%3d %9f", patientPtr->id, patientPtr->systolic,
patientPtr->diastolic,(patientPtr->ldlchol/patientPtr->hdlchol));
}
}
Thanks |
| sayword is offline | |
| | #2 |
| Code Goddess Join Date: Sep 2001
Posts: 9,661
| >I am having a little problem with this program The first argument of fprintf is a FILE *, not a format string. Code: else
{
fprintf(patrpt,"%20s", "Patient's Report");
fprintf(patrpt,"%s", "Patient ID Blood Pressure Cholesterol Ratio\n");
for (x = 0; x <= i; x++)
{
fprintf(patrpt,"%8s %3d\\%3d %9f", patientPtr->id, patientPtr->systolic,
patientPtr->diastolic,(patientPtr->ldlchol/patientPtr->hdlchol));
}
}
__________________ My best code is written with the delete key. |
| Prelude is offline | |
| | #3 |
| Registered User Join Date: Feb 2003
Posts: 33
| thanks buddy :-) |
| sayword is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Struct with a ptr to a dynamically allocated array of other structures :( | michael- | C Programming | 10 | 05-18-2006 11:23 PM |
| Array of struct pointers - Losing my mind | drucillica | C Programming | 5 | 11-12-2005 11:50 PM |
| Passing pointers between functions | heygirls_uk | C Programming | 5 | 01-09-2004 06:58 PM |
| Contest Results - May 27, 2002 | ygfperson | A Brief History of Cprogramming.com | 18 | 06-18-2002 01:27 PM |
| what does this mean to you? | pkananen | C++ Programming | 8 | 02-04-2002 03:58 PM |