read/write/swap problem for array of strings

so i have a list of reserved words i have to read in from an input file sort and then write to an output file. nothing except the title is being written. any help would be greatly appreciated. full driver programs to large but here's the part i'm struggling with. Thanks in advance. (input data below)

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
void sortEmRes(int a, string res[]) 
{
	for (int i = 0; i < a - 1; i++) 
	{
		for (int j = 0; j < a - 1; j++) 
		{
			if (res[j] > res[j + 1])
				swapEm(res[j], res[j + 1]);
		}
	}
}

void readEmRes(string res[]) {
	ifstream inf("reserve.dat");
	int i = 0;
	while (!inf.eof() && i < maxState) {
		inf >> res[i];
		i++;
	}
	sortEmRes(i, res);
}

void writeEmRes(ofstream& outf, string res[]) 
{
	outf << setw(50) << "Reserved Words" << endl;
	int i = 0;
	while (i < maxState) 
	{
		outf << setw(5) << left << res[i] << " ";
		i++;
	}
	outf << right << endl;
}


reserve.dat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
print
input
end
read
goto
for
if
then
step
rem
to
next
or
and

sortEmRes(...) is wrong. It should be:
1
2
3
4
5
6
7
8
9
10
11
void sortEmRes(int a, string res[]) 
{
	for (int i = 0; i < a - 1; i++) 
	{
		for (int j = i + 1; j < a - 1; j++) 
		{
			if (res[i] > res[j])
				swapEm(res[j], res[j + 1]);
		}
	}
}
Not tested.

But that shouldn't be the reason that nothing but the title is written. You should post a minimal compilable example in order to reproduce the problem.

What you can do to determine the proble is add some debug couts.
Topic archived. No new replies allowed.