This compiles perfectly fine.
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cmath>
using namespace std;
const int NUM_PLAYERS = 32;
struct wrType
{
string name[NUM_PLAYERS];
string team[NUM_PLAYERS];
int catches[NUM_PLAYERS];
int yards[NUM_PLAYERS];
int td[NUM_PLAYERS];
double ypc[NUM_PLAYERS];
};
void populateList(wrType[], ifstream&);
int main(int args, char* argv[])
{
wrType *wide;
char select;
ifstream in;
in.open(argv[1]);
if (!in.is_open())
{
cout << "File not found!" << endl;
exit(0);
}
/*populateList(wrType wide, ifstream in); code causing error*/
}
void populateList(wrType wide, ifstream in)
{
for(int x=0;x<NUM_PLAYERS;x++)
{
in >> wide.name[x];
in >> wide.catches[x];
in >> wide.yards[x];
in >> wide.td[x];
wide.ypc[x] = (ceil((static_cast<double>(wide.yards[x])/static_cast<double>
(wide.catches[x])) * 10))/10;
in >> wide.team[x];
}
for(int x=0;x<NUM_PLAYERS;x++)
{
cout << wide.name[x] << " ";
cout << wide.catches[x] << " ";
cout << wide.yards[x] << " ";
cout << wide.ypc[x] << " ";
cout << wide.td[x] << " ";
cout << wide.team[x];
cout << endl;
}
};
As soon as I uncomment the following code
'populateList(wrType wide, ifstream in);'
I get the following error
'ld returned 1 exit status error'
After compiling. I have looked at many forums and have not been able to solve the problem. We recently got into structs and classes and I am not sure if I am misunderstanding a concept or how to get this to work.
The code is supposed pass a file through the command line and then later on be able to access it and sort with bubble sort by different stats of football players which is 32 players. I don't want my hand held which is why I left the rest out for me to struggle with later. The code works without the function and within main but as soon as I try and call the function with the code I have, it gives me an error as stated.
Also when I try to pass them as pointers the it gives me a can't convert myType* to myType
Aucun commentaire:
Enregistrer un commentaire