need assistance with getting data and putting it into output

I'm very new, not exactly sure what i'm doing, it compiles but crashes when I input the file name, before i changed it to this it wasnt printing out the contents of the file


#include <fstream>
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

struct animalType
{
string species;
string name;
int id;
int yearAquired;
};


typedef animalType infoType ;

struct nodeType
{
infoType info;
nodeType *link;
};

// Function Prototypes

void getData (ifstream& inFile, animalType list[], int& listSize);
void print(nodeType *);
nodeType * makeIt (ifstream& inFile);
void spacer();
animalType getOne ( ifstream& dataIn );
void printOne ( animalType one) ;


int main ()
{
int number;
string file;
animalType list2 [50];
nodeType *list;

ifstream inFile; //input file stream variable
cout << "Please enter a .txt file\n";//z1.txt, etc
cin >> file;
cout << endl;

inFile.open(file.c_str());

//ifstream inFile;
// inFile.open("roster1.txt");
if (!inFile)
{
cout << "file not found";
return 0;
}


getData(inFile, list2, number);

list = makeIt (inFile);
print(list);










return 0;
}


void getData(ifstream& inFile, animalType list[], int& listSize)
{


animalType item ;
listSize = 0;
inFile.ignore ( 200,'\n');

inFile >> item.species >> item.name >> item.id >> item.yearAquired;


while (inFile )
{
nodeType *animal;
nodeType *current;
current = animal;

list [listSize ] = item ;
listSize++;

inFile >> item.species >> item.name >> item.id >> item.yearAquired;


while (current != NULL)
{
printOne ( current->info) ;
cout << endl;
current = current->link;
}
}



inFile.close () ;
}



// inputs employee data from the inFile
// inserts the employeeType structs into a linked list
// in the same order as the input
// returns a pointer to the first node in the list.

nodeType * makeIt (ifstream& inFile)

{
nodeType * species, *last, *temp;
infoType x;

species = NULL;

x = getOne (inFile ) ;
while (inFile)
{
temp = new nodeType;
temp->info = x;
temp->link = NULL;

if ( species == NULL )
{
species = temp;
last = temp;
}
else
{
last->link = temp;
last = temp;
}

x = getOne (inFile ) ;
}

return species ;

}

void print(nodeType *species)

/* print displays the members of each element of the
linked list of structures of type nodeType; the formal parameter
first points to the first node in the list.

*/

{


cout << setw(15)<<left <<"Species"
<< setw(15)<<left<< "Name"
<< setw(15)<<left << "ID"
<< "Year aquired" << endl;


cout << setw(15)<<left <<"======="
<< setw(15)<<left<< "===="
<< setw(15)<<left << "=="
<< "============" << endl <<endl;


cout << endl;
cout << "================================\n\n"
<< "End of the list \n\n";

}




animalType getOne ( ifstream& dataIn )
{
animalType one;


dataIn >> one.species >> one.name >> one.id >> one.yearAquired;


return one;
}


//////////////////////
//print out one animalType struct
void printOne ( animalType one)
{
cout << setw(15)<<left << one.species
<< setw(15)<<left<< one.name
<< setw(15)<<left << one.id
<< one.yearAquired << endl;
}

void spacer()
{
cout << "==========================================================================" << endl;
}

I think my problem is in the main, getData, or printOne... or all
Topic archived. No new replies allowed.