array of structs

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<iostream>
#include<fstream>
using namespace std;

void copyFile (char [], char []);

const int 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!

Thanks in advance
Last edited on
should line 18 be char info[UNIQUE];?
Last edited on
hahahaha! I guess it WAS that simple! Thanks mate!
Topic archived. No new replies allowed.