
-----------------------------------
chopficaro
Sat May 10, 2008 5:58 pm

fread/fwrite
-----------------------------------
ok i got past that part i posted about before, now im having some more trouble. i can add 2 patients easily to the file. then i try to display them. it displays the first one just fine, but the second it tries to display the first value in the 
#include "iostream"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "process.h"
#define maxpatients 8
using namespace std;

void main();



struct namestruct
{
	char firstName[32];
	char middleI;
	char lastName[32];
};

struct addressstruct
{
	char streetAddress[32];
	char city[32];
	char state[3];
	int zipcode;
};

struct locationstruct
{
	int numFloor;
	int numRoom;
	unsigned char subLocation;
};

struct geninfostruct
{
	addressstruct address;
	char phoneNumber[12];
};

struct insuranceinfostruct
{
	char nameCarrier[32];
	geninfostruct insurancegeninfo;
	float deductable;
};

struct datestruct
{
	int day;
	int month;
	int year;
};

struct patientstruct
{
	namestruct namepatient;
	int age;
	geninfostruct geninfopatient;
	insuranceinfostruct insurence;
	datestruct dischargedate;
	locationstruct locationpatient;
	char information[1024];
};



char menu()
{
	char option1;
	do
	{
	system("cls");
	printf("press a coresponding key and then press enter to choose an option:\n1. open a file\n2. write database to file\n3. display patients\n4. find a patient\n5. add a patient\n6. delete a patient\n7. move a patient\n8.print out patients by discharge date\n");
	option1 = getchar();
	}
	while (option1 '7');
	
	fflush(stdin);
	
	return option1;
}

void addpatient(patientstruct (*patientstructpointer)[maxpatients], int (*count)=0)
{
	patientstruct patientstruct1[maxpatients];
	int numread;
	char yesno;
	FILE *fp;
	fp=fopen("c:\\patientdirectory.txt","r");
	if(fp==NULL)
	{
		printf("file not found. create one?y/n");
		fflush(stdin);
		do
		{
//			scanf_s("%c",&yesno);
			cin>>yesno;
			switch(yesno)
			{	
				case 'y':
					break;
				case 'n':
					main();
					break;
				default:
					printf("please enter y for yes or n for no and press enter");
					break;
			}
		}while(yesno!='y');
	}
	else
	{
		while (!feof(fp))
		{
			numread = fread((patientstructpointer)[*count],sizeof(*patientstructpointer),1,fp);
			(*count)++;
		}
	}


		





	system("cls");

	fflush(stdin);
	printf("\nEnter the patient's first name\n");
	gets_s((*patientstructpointer)[*count].namepatient.firstName);
	fflush(stdin);
	printf("\nEnter the patient's middle initial\n");
	(*patientstructpointer)[*count].namepatient.middleI=getchar();
	fflush(stdin);
	printf("\nEnter the patient's last name\n");
	gets_s((*patientstructpointer)[*count].namepatient.firstName);
	fflush(stdin);
	printf("\nEnter the patient's age\n");
	scanf_s("%d",&(*patientstructpointer)[*count].age);
	fflush(stdin);
	printf("\nEnter the patient's state of residence\n");
	gets_s((*patientstructpointer)[*count].geninfopatient.address.state);
	printf("\nEnter the patient's city of residence\n");
	gets_s((*patientstructpointer)[*count].geninfopatient.address.city);
	fflush(stdin);
	printf("\nEnter the patient's zipcode of residence\n");
	scanf_s("%d",&(*patientstructpointer)[*count].geninfopatient.address.zipcode);
	fflush(stdin);
	printf("\nEnter the patient's street address of residence\n");
	gets_s((*patientstructpointer)[*count].geninfopatient.address.streetAddress);
	fflush(stdin);
	printf("\nEnter the patient's phone number\n");
	gets_s((*patientstructpointer)[*count].geninfopatient.phoneNumber);
	fflush(stdin);
	printf("\nEnter the patient's insurance carrier's name\n");
	gets_s((*patientstructpointer)[*count].insurence.nameCarrier);
	fflush(stdin);
	printf("\nEnter the patient's insurance carrier's state\n");
	gets_s((*patientstructpointer)[*count].insurence.insurancegeninfo.address.state);
	fflush(stdin);
	printf("\nEnter the patient's insurance carrier's city\n");
	gets_s((*patientstructpointer)[*count].insurence.insurancegeninfo.address.city);
	fflush(stdin);
	printf("\nEnter the patient's insurance carrier's zipcode\n");
	scanf_s("%d",&(*patientstructpointer)[*count].insurence.insurancegeninfo.address.zipcode);
	fflush(stdin);
	printf("\nEnter the patient's insurance carrier's street address\n");
	gets_s((*patientstructpointer)[*count].insurence.insurancegeninfo.address.streetAddress);
	fflush(stdin);
	printf("\nEnter the patient's insurance carrier's deductable\n");
	scanf_s("%f",&(*patientstructpointer)[*count].insurence.deductable);
	fflush(stdin);
	printf("\nEnter the patient's year of discharge\n");
	scanf_s("%d",&(*patientstructpointer)[*count].dischargedate.year);
	fflush(stdin);
	printf("\nEnter the patient's month of discharge\n");
	scanf_s("%d",&(*patientstructpointer)[*count].dischargedate.month);
	fflush(stdin);
	printf("\nEnter the patient's day of discharge\n");
	scanf_s("%d",&(*patientstructpointer)[*count].dischargedate.day);
	fflush(stdin);
	printf("\nEnter the patient's floor number\n");
	scanf_s("%d",&(*patientstructpointer)[*count].locationpatient.numFloor);
	fflush(stdin);
	printf("\nEnter the patient's room number\n");
	scanf_s("%d",&(*patientstructpointer)[*count].locationpatient.numRoom);
	fflush(stdin);
	printf("\nEnter the patient's location number\n");
//location
	((*patientstructpointer)[*count].locationpatient.subLocation)=1;
	int locationnumber;
	scanf_s("%d",&locationnumber);
		switch(locationnumber)
		{	
		case 1:
			break;
		case '2':
			((*patientstructpointer)[*count].locationpatient.subLocation)=((*patientstructpointer)[*count].locationpatient.subLocation)