Pointer problem

I am writing a program that has read into a file of list of presidents, lists and sorts them alphabetically, and has their corresponding chronological number. As you can see, it also shows their successor's chrono number.

MY QUESTION: How do I use a pointer to replace the numbers in the NEXT column to the appropriate alpha number? For example, John Adams needs to have 22 instead of 3, referring to Thomas Jefferson.

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

void main()
{
  struct{int chronum; char pname[25]; int next;} plist[50], temp;
  int n=0, i, end, maxindex;

  ifstream fin;
  ofstream fout;
  fin.open("prez.dat");
  fin >> plist[n].pname;
  fout.open("output.dat");

  fout << right << setw(8) << "Alpha #" <<  setw(12) << "Chronum" << setw(25) << "Pres. Name" << setw(10) << "Next" << endl << endl;

  while(!fin.eof())
  {
    plist[n].chronum = n+1;
    n++;
    fin >> plist[n].pname;
  }
  
  for(end=n-1; end>0; end--)
  {
    maxindex = 0;
    for(i=0; i<=end; i++)
    {
      if(strcmp(plist[i].pname, plist[maxindex].pname)>0)
        maxindex=i;
      temp = plist[maxindex];
      plist[maxindex]=plist[end];
      plist[end]=temp;
    }
	
  }
  end=0;
  for(end=n-1; end>0; end--)
  {
	for(i=0; i<=end; i++)
	{
		plist[i].next = plist[i].chronum+1;
	}
  }

  for(i=0; i<=43; i++)
    fout << right << setw(8) << i << setw(12) << plist[i].chronum << setw(25) << plist[i].pname << setw(10) << plist[i].next << endl;
}


 Alpha #     Chronum               Pres. Name      Next

       0           2               ADAMS,JOHN         3
       1           6        ADAMS,JOHN_QUINCY         7
       2          21           ARTHUR,CHESTER        22
       3          15           BUCHANAN,JAMES        16
       4          41              BUSH,GEORGE        42
       5          43       BUSH,GEORGE_WALKER        44
       6          39             CARTER,JIMMY        40
       7          22         CLEVELAND,GROVER        23
       8          24        CLEVELAND2,GROVER        25
       9          42          CLINTON,WILLIAM        43
      10          30          COOLIDGE,CALVIN        31
      11          34        EISENHOWER,DWIGHT        35
      12          13         FILLMORE,MILLARD        14
      13          38              FORD,GERALD        39
      14          20           GARFIELD,JAMES        21
      15          18            GRANT,ULYSSES        19
      16          29           HARDING,WARREN        30
      17          23        HARRISON,BENJAMIN        24
      18           9   HARRISON,WILLIAM_HENRY        10
      19          19         HAYES,RUTHERFORD        20
      20          31           HOOVER,HERBERT        32
      21           7           JACKSON,ANDREW         8
      22           3         JEFFERSON,THOMAS         4
      23          17           JOHNSON,ANDREW        18
      24          36           JOHNSON,LYNDON        37
      25          35             KENNEDY,JOHN        36
      26          16          LINCOLN,ABRAHAM        17
      27           4            MADISON,JAMES         5
      28          25         MCKINLEY,WILLIAM        26
      29           5             MONROE,JAMES         6
      30          37            NIXON,RICHARD        38
      31          44             OBAMA,BARACK        45
      32          14          PIERCE,FRANKLIN        15
      33          11               POLK,JAMES        12
      34          40            REAGAN,RONALD        41
      35          32       ROOSEVELT,FRANKLIN        33
      36          26       ROOSEVELT,THEODORE        27
      37          27      TAFT,WILLIAM_HOWARD        28
      38          12           TAYLOR,ZACHARY        13
      39          33             TRUMAN,HARRY        34
      40          10               TYLER,JOHN        11
      41           8         VAN_BUREN,MARTIN         9
      42           1        WASHINGTON,GEORGE         2
      43          28           WILSON,WOODROW        29
Topic archived. No new replies allowed.