C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-13-2003, 09:31 AM   #1
Registered User
 
Join Date: Feb 2003
Posts: 33
Help me with a program involving structs and struct pointers?

I am having a little problem with this program
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);
}
The errors i am getting are:
"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   Reply With Quote
Old 03-13-2003, 09:38 AM   #2
Code Goddess
 
Prelude's Avatar
 
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));
  }
}
-Prelude
__________________
My best code is written with the delete key.
Prelude is offline   Reply With Quote
Old 03-13-2003, 09:40 AM   #3
Registered User
 
Join Date: Feb 2003
Posts: 33
thanks buddy

:-)
sayword is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 04:01 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22