Passing a dynamic array of structures to a function

Hello,

I have to create a program that lets the user enter how many speakers he/she needs to enter information for,then let them input this information.

I've dynamically allocated an array of structures,and I have written code that will allow the user to specify how many speakers they need to input info in for, that seems to have gone well, however, i'm trying to pass this dynamically allocated structure to a function that will do all that cluttered code, and allow me to call it on multiple occasions.

I seem to be having trouble passing that allocated structure to a function,
below are the two error codes that I will get as well as my code so far,If anyone could help shed some light on this problem for me, It would very much appreciated


1
2
Error	1	error LNK2019: unresolved external symbol "void __cdecl EnterSpeaker(struct Speakers *,int)" (?EnterSpeaker@@YAXPAUSpeakers@@H@Z) referenced in function _main	9-11.obj
Error	2	fatal error LNK1120: 1 unresolved externals	C:\Users\Nick Gingerella\Desktop\Program Projects\Lesson 3 Homework\11-9\Debug\11-9.exe



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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;



// int const for array sizes
const int INFO_COUNT = 4;
const int NAME_SIZE = 20;
const int TOPIC_SIZE = 30;
const int PHONE_SIZE = 15;

//structure definition
struct Speakers
{
	char name[NAME_SIZE];
	char phone[PHONE_SIZE];
	char topic[TOPIC_SIZE];
	float fee;
};

//function prototypes
void Menu2();
//the problem might be here
void EnterSpeaker(Speakers *, int);


int main()
{
	
	

	cout << "11.9 Speakers Bureau\n\n\n";

	cout << "How many speakers do you have information for?\n";
	
	int num_of_speakers;
	do
	{
		cout <<"(Enter a positive number)\n";
		cin >> num_of_speakers;
		cout << "\n";
	}
	while(num_of_speakers < 1);


	//the problem might be here
	Speakers *spkrPtr;
	spkrPtr = new Speakers[num_of_speakers];
	
	
	/*

	this code by itself will work, this is the code that I put in the function
	already, I simply want to pass the dynamic array of structures to a function 
	that does all of this.


	for(int count = 0;count < num_of_speakers; count++)
	{
		cin.ignore();
		cout << "Name: ";
		cin.getline(speaker[count].name, NAME_SIZE);
		cout << "\n";
		cout << "Phone: ";
		cin.getline(speaker[count].phone, PHONE_SIZE);
		cout << "\n";
		cout << "Topic: ";
		cin.getline(speaker[count].topic, TOPIC_SIZE);
		cout << "\n";
		cout << "Fee\n";
		do
		{
			cout << "(Must be a positive number)\n$";
			cin >> speaker[count].fee;
			cout << "\n\n";
		}
		while(speaker[count].fee < 1);

		cout << "Name: ";
		cout << speaker[count].name;
		cout << "\n";
		cout << "Phone: ";
		cout << speaker[count].phone;
		cout << "\n";
		cout << "Topic: ";
		cout << speaker[count].topic;
		cout << "\n";
		cout << "Fee: ";
		cout << speaker[count].fee;
		cout << "\n\n";
	}
	*/

		//the problem might be here
		EnterSpeaker(spkrPtr, num_of_speakers);	
	


	




	










	return 0;
}






void Menu2()
{
cout << "What action would you like to take?\n";
cout << "-------------------------------------\n";
cout << "1.View a speakers information\n";
cout << "2.Add a new speaker\n";
cout << "3.Change a speakers information\n";
cout << "4.End Program\n";
}


//The problem might be here
void EnterSpeakers(Speakers *spkr, int num_spkrs)
{

	for(int count = 0;count < num_spkrs; count++)
	{
		cin.ignore();
		cout << "Name: ";
		cin.getline(spkr[count].name, NAME_SIZE);
		cout << "\n";
		
		cout << "Phone: ";
		cin.getline(spkr[count].phone, PHONE_SIZE);
		cout << "\n";
		
		cout << "Topic: ";
		cin.getline(spkr[count].topic, TOPIC_SIZE);
		cout << "\n";
		
		cout << "Fee\n";
			do
			{
				cout << "(Must be a positive number)\n$";
				cin >> spkr[count].fee;
				cout << "\n\n";
			}
			while(spkr[count].fee < 1);

		cout << "Name: ";
		cout << spkr[count].name;
		cout << "\n";
		
		cout << "Phone: ";
		cout << spkr[count].phone;
		cout << "\n";
		
		cout << "Topic: ";
		cout << spkr[count].topic;
		cout << "\n";
		
		cout << "Fee: ";
		cout << spkr[count].fee;
		cout << "\n\n";
	}



}
 













Your definition is called "EnterSpeakers" but your prototype/call uses "EnterSpeaker".
......Thank you very, very much,

Im gonna go beat my head in with a ice cream scoop for the next half hour for making that mistake.
Topic archived. No new replies allowed.