I've been trying for a while now to understand how an array of structs would work. I'm trying to read in an external file and read that information into an array of structs, I'm trying to do this without declaring the struct globally.
Here's my code:
#include<iostream>
#include<fstream>
usingnamespace std;
void copyFile (char [], char []);
constint UNIQUE = 100;
int main()
{
struct Data {
char text[21];
int count;
};
Data array[UNIQUE];
char info[array]; //error c2057
char inputName [21];
cout << "Enter the name of the file to open: ";
cin >> inputName;
copyFile (inputName, info);
}
void copyFile (char fileName [], char info [])
{
ifstream infile;
int count = 0;
infile.open (fileName);
int ch;
while ((ch = infile.peek()) != EOF)
{
infile.getline (info, 100);
cout << info << endl;
count++;
}
cout << "\nThere were " << count << " lines read.\n";
cout << endl;
infile.close();
}
My error is coming from line 18 which says I that a constant is suppose to go there. Any suggestions?
The idea is to create an array of structs that I can then use to pass on to other functions. Which I assume is possible but I may be ignorant on the subject. Enlighten me please!