Help me with a program involving structs and struct pointers?

This is a discussion on Help me with a program involving structs and struct pointers? within the C Programming forums, part of the General Programming Boards category; I am having a little problem with this program Code: #include<stdio.h> void printstruct(struct patient *, int); struct patient { char ...

  1. #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

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >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.

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    33
    thanks buddy

    :-)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 05-18-2006, 11:23 PM
  2. Array of struct pointers - Losing my mind
    By drucillica in forum C Programming
    Replies: 5
    Last Post: 11-12-2005, 10:50 PM
  3. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 05:58 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 02:58 PM

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