I've provided the whole program so anyone can tell what I'm trying to accomplish. In my last two sub-functions how am I going to keep the loop going after it finds a name (if there is more than one occurance of that name) I don;t want the loop t stop after finding the name just once. I want it to display all occurances of that name.
Code:
#include <iostream>
#include <iomanip>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <fstream>
using namespace std;
/***************************************************************
Struct: person
***************************************************************/
struct person
{
char personName[30];
int amLevel;
int noonLevel;
int pmLevel;
};
void showAll(person [], char *[], int);
void showName(person[], char *[], int, int);
void showNameLevel(person[], char *[], int, int);
int main(int argc, char *argv[])
{
ifstream inFile;
person patient[25];
int i;
inFile.open("c:\\Z089933sugar.dat",ios::in|ios::binary);
if(inFile.fail())
{
cout<< "Error! Make sure file exists.";
exit(1);
}
inFile.read((char*)&patient[i],sizeof(person));
while(inFile && i <= 24)
{
i++;
inFile.read((char*)&patient[i],sizeof(person));
}
inFile.close();
switch(argc)
{
case 1:
showAll(patient, argv, i);
break;
case 2:
showName(patient, argv, i, argc);
break;
case 3:
showNameLevel(patient, argv, i, argc);
break;
default:
cout<< "Too many arguments!";
}
return 0;
}
/*********************************************
Function: showAll
Use:
Arguments:
Returns:
*********************************************/
void showAll(person patient[], char * argv[], int max)
{
int i;
for (i = 0; i < max; i++)
{
cout << "\nPatient:" << patient[i].personName;
cout << "\n am level:" << patient[i].amLevel;
cout << "\n pm level:" << patient[i].pmLevel;
cout << "\n noon level:" << patient[i].noonLevel;
}
return;
}
/*********************************************
Function: showName
Use:
Arguments:
Returns:
*********************************************/
void showName(person patient[], char * argv[], int max, int argc)
{
int i;
int found;
for(i = 0; i < max; i++)
{
found = strcmp(argv[1], patient[i].personName);
if(found == 0)
{
}
/*********************************************
Function: showNameLevel
Use:
Arguments:
Returns:
*********************************************/
void showNameLevel(person persons[], char * argv[], int max, int argc)
{
}
Any help would be appreciated.