Presidential Database

The database that i need to use is in alphabetical order by presidents names.The chronum is what number president the particular individual was.The pointer(next prez) filed links a president to his successor.

so I need to print out something like this:

location chronum presidents name next prez
0 2 Adams,john 22
1 6 Adams,jons_quincy 21
2 21 Arthur,Chester 7
. . .... .
. . .... .
. . .... .
42 1 Washington,George 0
43 28 Wilson,Woodrow 16

this is what I got so far:

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
#include<fstream>
#include<iostream>
#include<cstring>
using namespace std;

int main()
{
	struct
	{
		int chronom;
		char pname[25];
		int next;
	}
	char plist[50];
	int temp;
	int i;
	int rightmost;
	int imax;
	ifstream fin;

	fin.open("prez.dat");
	int n=0;
		fin>>plist[n].pname;
	while(!fin.eof())
	{
		plist[n].chronom = n+1;
		n++;
		fin>>plist[n].pname;
	}
	for(rightmost=n-1;rightmost>0;rightmost--)
	{
		imax=0;
		for(i=1;i<=rightmost;i++)
			if(strcmp(plist [i].pname,plist[imax].pname)>0)
				imax=i;
		temp = plist[imax];
		plist[imax]=plist[rightmost];
		plist[rightmost]=temp;
	}

	cout<<"location\tchronum\tpresident's name\tnext prez"<<endl<<endl;
	return 0;
}
So?
What exactly does the input file look like? According to your description the input file is ordered alphabetically. However your program assumes it is ordered chronologically.
@Bazzy I cant run the program and I dont know what to do after cout.
@pangalactic I am sorry.I need the output in alphabetical order the input is in chronological.
Topic archived. No new replies allowed.