If you actually need to pass this newly allocated array back to your main() function, then you will need a double pointer. Your code will look similar to this.
Code:
int readData(Point base[2], Vertex** vertices);
int main(void)
{
Point base[2];
Vertex *vertices;
int i;
readData(base,&vertices);
for (i=0; i<48; i++)
cout << vertices[i].bldgId << endl;
//Clean up memory when done
delete []vertices;
return 0;
}
int readData(Point base[2], Vertex** vertices)
{
int nPts = 0;
int i;
*vertices = new Vertex [48];
ifstream fin("survey.dat");
if (!fin)
{
cout << "Could not find file.\n";
return 0;
}
while (fin>>(*vertices)[nPts].bldgId)
{
cout<<(*vertices)[nPts].bldgId << endl;
nPts++;
}
cout << "nPts:" << nPts << endl;
return 1;
}
You can use a single pointer (Vertex *vertices) if you allocate the array in the main() function.
Also be sure that nPts is 48 at the end of the function, otherwise you may be going past the end of the array.
If nPts is your return value, then change the last line above to:
return nPts;