My program refuses to pass array. Where am I going wrong?

Hey, I have been having a complete nightmare trying to pass an array to a function but it only passes the first number and removes the rest. I have read it over and over try to find the issue but I can't find one. The code I am using is:

void FindResponse(int codes[15]); //Function Prototype

int codes[15]; //Declaring the array inside main

FindResponse(codes); //calling the function.

It works up until passing the array, and as soon as it is passed it screws up. No idea whats wrong. Any help would be brilliant. Cheers
In the function prototype you do not put the size of the array inside the brackets, take that out.

void FindResponse(int codes[], int);

int would be the size of the array, when you call it, do this

FindResponse(codes, 15)
How is FindResponse implemented?
I don't notice anything wrong with the code. Post the entire program and when you post use code tags. There's a little menu next to the text field click on the button that looks like this <> it will make the program look better and will be easier to read. Like this

1
2
3
4
5
void FindResponse(int codes[15]); //Function Prototype
 
int codes[15]; //Declaring the array inside main
 
FindResponse(codes); //calling the function. 


if you use code tags you will get more responses to your questions
Here is the full 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
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
199
200
201
202
203
204
205
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>

#define SLength 10
#define SAmount 10
using namespace std;


void FindResponse(int KeyCodes[15]);
int comparison(int codes[15], int responses[15]);
void CompareCodes(ifstream &ResponseFile, int Codes[15]);
void ChooseBestMatch(struct BestResponses Best[15]);

struct BestResponses{
	int Matches;
	int TotalMatches;
	int MatchPercentage;
	string Reply;
};

int main()
{
	char ChatIn[SAmount][SLength];

	
	string line;
	string keyword;
	string UserIn;
	int code;
	int count;
	char Key[10];
	int Codes[15];


	ifstream KeyWords("Keywords.txt");


	if(KeyWords.is_open())
	{
		while(ChatIn[0]!="Bye")
		{
			for(int i=0;i<15;i++)
			{
				Codes[i]=-1;
			}
			count=0;
			getline(cin, UserIn);
			stringstream Input(UserIn);
			Input>>ChatIn[0]>>ChatIn[1]>>ChatIn[2]>>ChatIn[3]>>ChatIn[4]>>ChatIn[5]>>ChatIn[6]>>ChatIn[7]>>ChatIn[8]>>ChatIn[9];

		
			while(KeyWords.good())
			{
			
				getline(KeyWords,line);
				cout<<line<<endl;

				stringstream ToCode(line);
				ToCode>>Key>>code;
				for(int i=0;i<10;i++)
				{
					if(strcmpi(Key,ChatIn[i])==0&&KeyWords.good())
					{
						cout<<"Match, yay!"<<endl;
						Codes[count]=code;
						count++;
					}
				}
			}
		
			KeyWords.clear();
			KeyWords.seekg(0,ios::beg);
			FindResponse(Codes);
		}
		
	KeyWords.close();
	
	}
	else
	{
		cout<<"unable to open file";
	}
	return 0;
}

void FindResponse(int KeyCodes[15])
{
	
	ifstream ResponseFile("Responses.txt");

	if(ResponseFile.good())
	{
		CompareCodes(ResponseFile, KeyCodes);
	}
	else
	{
		return;
	}
}

void CompareCodes(ifstream &ResponseFile, int Codes[15])
{
	string FileLine;
	string LineChunk;

	BestResponses Best[15];

	int ChunkNumber;
	int NumMatches;
	float MatchPercent;
	int MatchNumber=0;

	//Below are sections
	int ID;
	int ResponseCodes[15];

	int NumCodes;
	string Reply;
	//End of sections

	while(getline(ResponseFile, FileLine))
	{
		for(int i=0;i<15;i++)
		{
			ResponseCodes[i]=0;
		}
		ChunkNumber=0;

		istringstream ResponseLine(FileLine);

		while(getline(ResponseLine, LineChunk,'|'))
		{
			istringstream Chunk(LineChunk);

			ChunkNumber++;
			
			switch(ChunkNumber)
			{
			case 1: Chunk>>ID;
				break;
			case 2: Chunk>>ResponseCodes[0]>>ResponseCodes[1]>>ResponseCodes[2]>>ResponseCodes[3]>>ResponseCodes[4]>>ResponseCodes[5]>>ResponseCodes[6]>>ResponseCodes[7]>>ResponseCodes[8]>>ResponseCodes[9]>>ResponseCodes[10]>>ResponseCodes[11]>>ResponseCodes[12]>>ResponseCodes[13]>>ResponseCodes[14];
				break;
			case 3: Chunk>>NumCodes;
				break;
			case 4: Chunk>>Reply;
				break;
			}
		}//while line loop end			
		
		NumMatches=comparison(Codes, ResponseCodes);
		MatchPercent=(NumMatches/NumCodes);
		MatchPercent=MatchPercent*100;
		
		if(MatchPercent>=25)			
		{
			 Best[MatchNumber].Matches=NumMatches;
			 Best[MatchNumber].TotalMatches=NumCodes;
			 Best[MatchNumber].MatchPercentage=MatchPercent;
			 Best[MatchNumber].Reply=Reply;
		}

		MatchNumber++;
	}//while end get file line
	ChooseBestMatch(Best);

	//reset stuff for next run
	ResponseFile.clear();
	ResponseFile.seekg(0,ios::beg);

}
void ChooseBestMatch(struct BestResponses Best[15])
{
	int BestMatch;
	BestMatch=0;
	for(int i=0;i<14;i++)
	{
		if(Best[i].Matches<Best[i+1].Matches)
		{
			BestMatch=i+1;
		}
	}
	cout<<Best[BestMatch].Reply<<endl;
}


int comparison(int Codes[15], int responseCodes[15])
{

	int matches=0;
			for(int i=0;i<15;i++)
				{
					for(int l=0;l<15;l++)
					{
						if(Codes[i]==responseCodes[l])
						{
							matches++;
							break;
						}
					}
				}
	return matches;

}
- As mentioned above, do not put the size of the array in your function prototype, or your function definition.
I tried that but it made no difference, still gave the same response.

- It should be something like this:

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


void arrayBlah( double [], int);

int main()
{
int bar=88;

double hold[bar];

// initialize values for w/e

arrayBlah(hold,bar);

getch(); // or whatever you like to use here
return 0;
}

void arrayBlah(double h[ ], int size)
{

// code here
// remember that arrays are passed by reference in c++
}
Made them changes:
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
int main()
{
	int const size=15;
	char ChatIn[SAmount][SLength];

	
	string line;
	string keyword;
	string UserIn;
	int code;
	int count;
	char Key[10];
	int Codes[size];


	ifstream KeyWords("Keywords.txt");


	if(KeyWords.is_open())
	{
		while(ChatIn[0]!="Bye")
		{
			for(int i=0;i<15;i++)
			{
				Codes[i]=-1;
			}
			count=0;
			getline(cin, UserIn);
			stringstream Input(UserIn);
			Input>>ChatIn[0]>>ChatIn[1]>>ChatIn[2]>>ChatIn[3]>>ChatIn[4]>>ChatIn[5]>>ChatIn[6]>>ChatIn[7]>>ChatIn[8]>>ChatIn[9];

		
			while(KeyWords.good())
			{
			
				getline(KeyWords,line);
				cout<<line<<endl;

				stringstream ToCode(line);
				ToCode>>Key>>code;
				for(int i=0;i<10;i++)
				{
					if(strcmpi(Key,ChatIn[i])==0&&KeyWords.good())
					{
						cout<<"Match, yay!"<<endl;
						Codes[count]=code;
						count++;
					}
				}
			}
		
			KeyWords.clear();
			KeyWords.seekg(0,ios::beg);
			FindResponse(Codes,size);
		}
		
	KeyWords.close();
	
	}
	else
	{
		cout<<"unable to open file";
	}
	return 0;
}

void FindResponse(int KeyCodes[], int size)
{
	
	ifstream ResponseFile("Responses.txt");

	if(ResponseFile.good())
	{
		CompareCodes(ResponseFile, KeyCodes);
	}
	else
	{
		return;
	}
}

Still the same...

- There is no problem with passing the array to the function here, the problem probably lies with your file handling

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

#include<iostream>
using namespace std;
void FindResponse(int [], int);
int main()
{
	int const size=15;
	int SAmount =10;
	int SLength=10;
	char ChatIn[SAmount][SLength];


	string line;
	string keyword;
	string UserIn;
	int code;
	int count;
	char Key[10];
	int Codes[size];

	for (int i=0;i<size;i++)
    {
        Codes[i]= ((i+1)*2);
    }


//	ifstream KeyWords("Keywords.txt");

/*
	if(KeyWords.is_open())
	{
		while(ChatIn[0]!="Bye")
		{
			for(int i=0;i<15;i++)
			{
				Codes[i]=-1;
			}
			count=0;
			getline(cin, UserIn);
			stringstream Input(UserIn);
			Input>>ChatIn[0]>>ChatIn[1]>>ChatIn[2]>>ChatIn[3]>>ChatIn[4]>>ChatIn[5]>>ChatIn[6]>>ChatIn[7]>>ChatIn[8]>>ChatIn[9];
/*

			while(KeyWords.good())
			{

				getline(KeyWords,line);
				cout<<line<<endl;

				stringstream ToCode(line);
				ToCode>>Key>>code;
				for(int i=0;i<10;i++)
				{
					if(strcmpi(Key,ChatIn[i])==0&&KeyWords.good())
					{
						cout<<"Match, yay!"<<endl;
						Codes[count]=code;
						count++;
					}
				}
			}

			KeyWords.clear();
			KeyWords.seekg(0,ios::beg);

			FindResponse(Codes,size);
		}

	KeyWords.close();

	}
	else
	{
		cout<<"unable to open file";
	}
	*/
	FindResponse(Codes,size);
	//system ("Pause");
	return 0;
}



void FindResponse(int KeyCodes[], int size)
{

	//ifstream ResponseFile("Responses.txt");
	/*

	if(ResponseFile.good())
	{
		CompareCodes(ResponseFile, KeyCodes);
	}
	else
	{
		return;
	}
	*/


	for(int f=0;f<size;f++)
    {
        cout<<"Number in arrayis : "<< KeyCodes[f]<<endl;
    }
}

Ok so what your are telling me to do works on its own so why is it not working in the program? Where have I screwed up?
Scrap that, problem solved... Not sure if my original thing worked but changed some stuff around and it now works. Thanks guys!
- No problem.
Topic archived. No new replies allowed.