Reading text from a file into an array

Hi there! I'm trying to write a program to take a file with various information about a film, and read the text into an array on the main program. I'm having trouble figuring out how to actually read the text into the file. I'm trying the getline function without much success. The error that I'm getting in the getMovie function is that there's no instance of the function that matches the argument list. If you can figure out what I'm doing wrong, I'd appreciate it a bunch. Thanks!

Main Function

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
  #include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>

using namespace std;

const int SIZE = 20;

struct dateType
{
	int month;
	int day;
	int year;
};

struct movieType
{
	string title;
	string director;
	int length;
	dateType theaterReleaseDate;
	dateType dvdReleaseDate;
	double productionCost;
	double firstYearRevenue;
};


int main()
{

	movieType movieLibrary[SIZE];

	ifstream myFile;

	myFile.open("P2_myBooks.dat");
	
	getMovie(movieLibrary, myFile);

	//addMovie(movieLibrary);

		//printMovie(movieLibrary);

		//allPrintMovie(movieLibrary);

		system("pause");

	return 0;

}

void addMovie(movieType addMov[])
{

	int i = 0;

	cout << "What position in the array?: ";
	cin >> i;

	cout << "Enter the title: ";
	cin >> addMov[i].title;
	cout << "Director: ";
	cin >> addMov[i].director;
	cout << "Length: ";
	cin >> addMov[i].length;
	cout << "Theater Release Date Day (Day, Month, Year): ";
	cin >> addMov[i].theaterReleaseDate.day >> addMov[i].theaterReleaseDate.month >> addMov[i].theaterReleaseDate.year;
	cout << "DVD Release Date Day (Day, Month, Year): ";
	cin >> addMov[i].dvdReleaseDate.day >> addMov[i].dvdReleaseDate.month >> addMov[i].dvdReleaseDate.year;
	cout << "Production Cost: ";
	cin >> addMov[i].productionCost;
	cout << "First year Revenue: ";
	cin >> addMov[i].firstYearRevenue;

	return;
}

void printMovie(movieType prMov[])
{
	string name;
	cout << "Which movie in the array would you like to print? Enter the title: ";
	cin >> name;

	for (int i = 0; i <= SIZE-1; i++)
		if (name == prMov[i].title)
		{
			cout << "Title: " << prMov[i].title;
			cout << "Director: " << prMov[i].director;
			cout << "Length: " << prMov[i].length;
			cout << "Theater Release Date : " << prMov[i].theaterReleaseDate.day << prMov[i].theaterReleaseDate.month << prMov[i].theaterReleaseDate.year;
			cout << "DVD Release Date Day : " << prMov[i].dvdReleaseDate.day << prMov[i].dvdReleaseDate.month << prMov[i].dvdReleaseDate.year;
			cout << "Production Cost: " << prMov[i].productionCost;
			cout << "First year Revenue: " << prMov[i].firstYearRevenue;
		}

	return;
}

void allPrintMovie(movieType allPrMov[])
{

	int i = 0;

	while (i < 100)
	{
		cout << "Title: " << allPrMov[i].title;
		cout << "Director: " << allPrMov[i].director;
		cout << "Length: " << allPrMov[i].length;
		cout << "Theater Release Date : " << allPrMov[i].theaterReleaseDate.day << allPrMov[i].theaterReleaseDate.month << allPrMov[i].theaterReleaseDate.year;
		cout << "DVD Release Date Day : " << allPrMov[i].dvdReleaseDate.day << allPrMov[i].dvdReleaseDate.month << allPrMov[i].dvdReleaseDate.year;
		cout << "Production Cost: " << allPrMov[i].productionCost;
		cout << "First year Revenue: " << allPrMov[i].firstYearRevenue;
		cout << endl;
		i++;
	}

	return;
}

void getMovie(movieType gtMov[], ifstream & myFile)
{
	if (myFile.is_open);
	{

		for (int i = 0; i <= SIZE; i++)
		{
			myFile.getline(gtMov[i].title);
			myFile.getline(gtMov[i].director);
			myFile.getline(gtMov[i].length);
			myFile.getline(gtMov[i].theaterReleaseDate.month, '/');
			myFile.getline(gtMov[i].theaterReleaseDate.day, '/');
			myFile.getline(gtMov[i].theaterReleaseDate.year);
			myFile.getline(gtMov[i].dvdReleaseDate.month, '/');
			myFile.getline(gtMov[i].dvdReleaseDate.day, '/');
			myFile.getline(gtMov[i].dvdReleaseDate.year, '/');
			myFile.getline(gtMov[i].productionCost);
			myFile.getline(gtMov[i].firstYearRevenue);

		}
	}
	
	return;
}


P2_myBooks.dat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
War of the Worlds
Byron Haskin
88
01/01/1953
01/01/2000
15000000.0
28000000.0

War of the Worlds
Stephen Spielberg
118
01/01/2005
01/01/2007
22000000.0
14000000.0
1
2
3
 In function 'int main()':
38:31: error: 'getMovie' was not declared in this scope
 In function 'void getMovie(movieType*, std::ifstream&)':

You have to either define your functions above the definition of main, or add function prototypes before you call the functions. The choice is yours.

See:
http://www.cplusplus.com/articles/yAqpX9L8/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
double someFunction( double, int ); // Prototype

int main()
{
	double a = 3.5;
	int b = 2;
	double c;
	
	c = someFunction( a, b );
}

double someFunction( double x, int y ) // Definition
{
	return x * y;
}
Last edited on
Topic archived. No new replies allowed.