Can't get my bubble sort to work...

I'm needing my program to sort by last name, but I'm not seeming to get that at all. I'm not sure what I'm doing wrong or missing. Any help or pointers?

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

struct Roster 
{
	string lname;
	string fname;
	char cheese;
};

const int MAXSIZE = 80;
char * givemename(char* fn);
int recordcount(const char * filename);

struct Roster* readarray(const int rcount, char *filename);
void readsurvey(const int rcount, const char * filename, struct Roster *);
int countp(const int rcount, struct Roster *MyRoster);
int countc(const int rcount, struct Roster *MyRoster);
void swap(struct Roster *MyRoster1,struct Roster * MyRoster2);
void BubbleSort (const int rcount, struct Roster*MyRoster);
void DrawRecords(const int rcount, struct Roster*MyRoster);
int drawsummary(const int rcount,const int pcount, const int ccount);

int main(void)
{
	char * filename = new char [MAXSIZE] ; 
	struct Roster * MyRoster;
	struct Roster *PassedRoster;
	int rcount=0, pcount=0, ccount=0;
	
	filename=givemename(filename); 
	rcount = recordcount(filename); 
	MyRoster = new struct Roster[rcount]; 
	readsurvey(rcount, filename, MyRoster);
	pcount = countp(rcount,MyRoster);
	ccount = countc(rcount,MyRoster);
	BubbleSort (rcount, MyRoster);
	DrawRecords(rcount,MyRoster);
	drawsummary(rcount,pcount,ccount);
	return 0;
}

char * givemename(char * fn) 
{
	ifstream myfile;
	cout << "Please enter a file name : ";
	cin >> fn;
	myfile.open(fn);
	while(!myfile.is_open())      
	{
		cout << "Invalid file name. Please re-enter: ";
		cin >> fn;
		myfile.open(fn);
	}
	return fn;
}
int recordcount ( const char* filename)
{
	int count=0;
	char inputline[MAXSIZE];
	ifstream myfile;
	myfile.open(filename);
	do
	{
		count ++;                
		myfile.getline(inputline, MAXSIZE);
		cout <<inputline<< endl;  
	}
	while(!myfile.eof());
	myfile.close();
	return count;
}
void readsurvey(const int rcount, const char * fn, struct Roster *mr)
{
	ifstream myfile;
	myfile.open(fn);
	for(int counter=0; counter<rcount ; counter++)
	{
		myfile >> mr[counter].lname >> mr[counter].fname >> mr[counter].cheese;
	}	
}
int countp(const int rcount, struct Roster* MyRoster)
{
	int count = 0;
	for (int i = 0; i<=rcount; i++)
		{
			if(MyRoster[i].cheese == 'P')
			{
				count ++ ;
			}
		}
		
	return count;
}
int countc(const int rcount, struct Roster* MyRoster)
{
	int count = 0;
	for (int i = 0; i<=rcount; i++)
		{
			if(MyRoster[i].cheese == 'C')
			{
				count ++ ;
			}
		}		
	return count;
}

void swap(struct Roster* MyRoster1,struct Roster* MyRoster2)
{
  struct Roster* temp = new struct Roster;
  temp = MyRoster1;
  MyRoster1 = MyRoster2;
  MyRoster2 = temp;
} 


void BubbleSort (const int rcount,struct Roster*MyRoster)
{  
	bool swapped=true; 
	int j = 0;
	 while (swapped)
     { 
        swapped = false;
		j++;
        for (int i=0; i<=rcount; i++)
           {
               if ( MyRoster[i].lname > MyRoster[i+1].lname)
                   {
                        swap(&MyRoster[i], &MyRoster[i+1]);
                        swapped=true; 
                    }
             }
      }
	 
}


void DrawRecords(const int rcount, struct Roster*MyRoster)
{
	cout <<"                THE CHEESECAKE REPORT                    " << endl
		 <<"LAST NAME          FIRST NAME            CAKE OR PIE  " << endl
		 <<"__________         __________            ___________   "<< endl;

	for(int i=0; i <= rcount; i++)
	{
		cout <<  MyRoster[i].lname << MyRoster[i].fname; 
		if(MyRoster[i].cheese == 'C')
			   { cout <<   "CAKE";}
		else 
				cout << "PIE";
		cout << endl;
	}

}

int drawsummary(const int rcount,const int pcount,const int ccount )
{
	cout << "Number of Records: " << rcount << endl << "Number of People"
		 "Who Believe Cheesecake is Pie: " << pcount << endl << "Number of " 
		 "People Who Believe Cheesecake is Cake: " << ccount << endl;

	return 0;
}



This is the text from the file I'm using. There are more but it's too long to post.

Barnes       Abigail    P
Peters       Adrian     P
Bayliss      Adrianna   P
Charlesworth Aimee      C
Pierre       Aleesha    C
Raines       Alison     C
Valleau      Alyssa     P
Furka        Amanda     P
Griffin      Amanda     C
John         Amanda     C
Mitchell     Amanda     C
Chandhok     Amanvir    P
Kuc          Amra       P
Colbert      Amy        P
Cole         Andrew     P
Kapec        Andrew     C
Kramer       Andrew     P
Moses        Andrew     C 
Vassil       Andrew     P 
Veldkamp     Anise      C
Popiel       Anthony    C
Myers        Arielle    P
Hargrove     Ashley     P
Kellem       Ashley     C
Johansen     Austin     C
Bassett      Blair      C
Tenenbaum    Bradlee    C 
Rochet       Brian      C 
Macke        Bridget    C
Farris       Brittany   P
Jones        Brittany   C
Waesche      Brittany   P
Troop        Brooke     C
Wilson       Caitlin    C
Dulgar       Caleb      C
Yarema       Carah      P
Fernandez    Carlos     C
Hughes       Caroline   C
Langston     Catherine  C
Zappia       Catherine  P
Griggs       Charles    C
Brunk        Chelsea    C
Mortimer     Chelsea    C
Byrnes       Chelsey    P
Ince-Ingram  Chloe      C
Love         Chloe'     C
Burmeister   Christophe C
Swingle      Cody       P
White        Corey      C
Safra        Cory       C
Rolle        Courtney   C
Herring      Craig      P
Paul         Daphnee    C
Taylor       David      C
Johnson      Elizabeth  C
Kaufmann     Elizabeth  P
Major        Elizabeth  C
Stein        Elizabeth  C
Hutchinson   Emily      C
Richeson     Emily      C
Swire        Emily      P
Todoroff     Eric       C
Hosch        Erica      C
Fuhrmann     Erika      P
Martin       Erika      C
Walsh        Erin       P
Revolinski   Forrest    P
Marte        Gabriel    C
Sjodin       Garry      C
Vickers      George     P
Reinhardt    Gregory    P
Reagin       Haley      P
Voss         Hayley     C
Silva        Heather    C
Tully        Hillary    C
Perez        Ivan       P
Hager        Jackson    P
Sonin        Jaclyn     C
Palad        Jager      C
Herndon      Jaimie     P
Laberdesque  Jared      P
Kelly        Jason      C
Allen        Jazmine    C
Guess        Jazmine    C
Lantz        Jeffrey    C
Chaaban      Jena       P
Carr         Jennifer   C
So           Jennifer   P
Oliver       Jessica    C
Smith        Jessica    C
Mazzoni      John       C
Orr          John       P
Brooks       Jonathan   P
Truong       Jonathan   P
Rochester    Jordan     P
Dasilva      Jose       C
Rhodes       Joseph     C
Rayner       Joshua     C
Fox          Joy        P
Gibson       Kaileigh   C
Latchford    Kaitlyn    P
Lankenau     Kaley      C
Guice        Katelin    P
Zelman       Katherine  C
Garnett      Kathleen   C
Sinn         Kathryn    P
Savage       Kayla      P
Worthington  Kelly      C
Debowes      Keri       C
Wheeler      Kevin      C
Stenson      Kheva      C
O'Hara       Kimberly   C
Shelton      Kiyah      C
Olfson       Kristina   C
Wright       Kristine   P
Biro         Krystina   C
Simons       Kyle       P
Berrien      Lakia      C
Palmer       Latreas    P
Cohen        Lauren     P
Hamilton     Lauren     C
Perez        Leandro    C
Cortelli     Leonard    C
Mesa         Lina       C
Abramo       Lindsey    C
Lefton       Lindsey    C
Morrison     Lindsey    C
Siegel       Lindsey    C
Robinson     Malik      C
Harkins      Mallory    C
Neiman       Marc       C
Diaz-Cortes  Marcelo    P
Summerford   Margaret   C
Marshall     Mariah     C
Lewis        Mario      P
Johnson      Marshall   C
Majeed       Mary       C
West         Matthew    P
Yanossy      Matthew    C
Bean         Meagan     C
Cain         Meagen     C
Carvajal     Megan      C
Khan-Karen   Megan      C
Moore        Megan      C
Mcduff       Meghan     C
Mayer        Meredith   C
Rainey       Michael    C
Genter       Michaelene C
Pyle         Molly      C
Mayo         Monica     P
Shepard      Morgan     C
Wicks        Morgan     C
Belafquih    Myriam     C
Jenkins      Nicholas   C
Nagatani     Nora       C
Tribue       Paris      C
Carlisle     Patrick    C
Casimiro     Paulo      P
Mcgrew       Phillip    C
Topic archived. No new replies allowed.