-
March 5th, 2014, 10:00 AM
#1
Need of Assistance #2
Hello again, I am currently writing a program that grabs information from a .dat file. When I go to debut I get this error.
Code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
// function step 1 - declare the prototypes
void sort(int n); // catches an integer number from the call
void swap(string *p1, string *p2); //catches the location of data in ram
// array number 1, declare & size the array
string *lname, *lyear, *ltype; // global because it needs to work with both main & sort
int main() {
int i, count = 0;
string type, name, year;
// open data file - create the fin object, - attach to datafile
ifstream fin("c:\\data2\\club.dat");
//count the records
while (!fin.eof()){
fin >> name >> type >> year;
count++;
}
fin.close();
//array size the arrays
ltype = new string[count];
lname = new string[count];
lyear = new string[count];
//load the arrays
fin.open("c:\\data2\\club.dat");
for (i = 0; i < count; i++) {
fin >> name[i] >> type[i] >> year[i];
}
fin.close();
sort(6);
cout << "Here is the Array - Sorted \n\n";
// output
for (i = 0; i < 6; i++)
cout << name[i] << "\t" << type[i] << "\t" << year[i] << "\n";
//delete the arrays
delete [] lname;
delete [] ltype;
delete [] lyear;
system("pause");
return 0;
}
//Function step 3 - The Function Definition
void sort(int n) {
int i, j, low; //Local variable - only exists in the sort function
for (i = 0; i < n - 1; i++){
low = i;
for (j = i + 1; j < n; j++)
if (lname[j] < ltype[low])
low = j;
if (i != low) { //Need a swap call for every array
swap(&lname[i], <ype[low]); //call to the swap function - the address if a[i] will be caught by
//the variable *p1 & the address of a[low] will be caught by *p2
swap(&lname[i], <ype[low]);
}
}
}
void swap(string *p1, string *p2) {
string temp = *p1;
*p1 = *p2;
*p2 = temp;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|