i have to make a program that facilitates the returning of lost pets to their owners, my current step to start is to make a function that populates the struct.
here is my current work:
#include <iostream>
#include <string>
#include <cstdlib>
#include <fstream>
#include <iomanip>
using namespace std;
const int SIZE = 100;
struct petRecord
{
char status[6];
char type[4];
char gender[8]; // sizes are just gueses
char breed[20];
int age;
char colour[20];
char suburb[20];
double phoneNo[50];
};
petRecord PetID[SIZE];
void readFile();
int counter;
char ch;
int main()
{
readFile();
system("PAUSE");
return EXIT_SUCCESS;
}
void readFile()
{
char ch;
ifstream inFile("pets.txt"); // opens file, prints contents = D
while(!inFile.eof())
{
for (counter = 0; counter < 100; counter++)
{
inFile.get (ch);
inFile.getline( PetID[counter].status, ' \n ');
inFile.getline(PetID[counter].type, ' \n ')
inFile.getline(PetID[counter].gender, ' \n ')
inFile.getline(PetID[counter].breed, ' \n ')
inFile.getline(PetID[counter].age, ' \n ')
inFile.getline(PetID[counter].colour, ' \n ')
inFile.getline(PetID[counter].suburb, ' \n ')
}
/* for (counter = 0; counter < 100; counter++)
{
cout << PetID[counter].status << " ";
//<< PetID[counter].type << " "
//<< PetID[counter].gender << " " // attempt to print info to see if it is storing
//<< PetID[counter].breed << " "
//<< PetID[counter].age << " "
//<< PetID[counter].colour << " "
//<< PetID[counter].suburb << " ";
//<< PetID[counter].phoneNo << " ";
}
*/
}
i have to populate info from a text file, which looks like this:
lost
cat
female
persian
0 3
black-white
mangerton
42614297
found
cat
male
siamese
5 6
tan
balgownie
42898942
lost
dog
female
pomeranian
5 4
black
dapto
42354461
found
cat
male
tiger
0 6
black-white
port kembla
42342706
lost
dog
female
cattle dog
5 1
white
dapto
42940424
my question is, am i on the right track? if not can you help point me the right way
if i am on the right track, where should i go from here, thanks in advance for assistance.