Arrays and Files

Hi I'm a beginner to c++ and I was assigned a project to declare an array of structs but the information is contained in a text file and I have to prompt the user for the file name and it takes that info and inputs it into an array in the output. The file contains a state, bird species, and the count of each different species. We also must use atleast 4 functions. This is what I have so far but the program doesnt seem to be working. Any advice?


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

using namespace std;

struct birdSpecies
{
int count;
string state,species;
};

void printOne ( birdSpecies one);
void printList(const birdSpecies list[], int listSize) ;
void getData(ifstream& inFile, birdSpecies list[], int& listSize);


int main ()
{

const int BIRD_SPECIES = 50;


birdSpecies list [BIRD_SPECIES] ;

string filename;
int number;
ifstream dataFile;
dataFile.open("one.txt");

cout << "Enter Text File" <<endl;
cin >> filename;


if ( !dataFile)
{
cout << "invalid file name \n";

return 1;
}

getData (dataFile, list, number);

cout << "Birds: " << endl;
printList( list, number) ;




}


void printOne ( birdSpecies one)
{
cout << fixed << showpoint << setprecision (10);
cout << "Species " << one.species ;

}

void printList(const birdSpecies list[], int listSize)
{
int looper ;

for ( looper = 0; looper < listSize ; looper++)
{
printOne ( list [looper] );
cout << endl ;
}
}

void getData(ifstream& inFile, birdSpecies list[], int& listSize)
{
birdSpecies item ;
listSize = 0;

inFile >> item.species >> item.count;

while (inFile )
{
list [listSize ] = item ;
listSize++;

inFile >> item.species >> item.count;
}
inFile.close () ;
}

I suggest you work with author of this post as you have the same problems: http://www.cplusplus.com/forum/general/98253/
Topic archived. No new replies allowed.