bubble sort not working with struct...
I need to sort the records by inv_num...I tried a regular bubble sort but it gives me and error, then I found an example on here that was using keys and key pointers, which is what I think I am supposed to do, so that is in comments on here....I just want it to sort and need help! Thanks!!!
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct info // Declares the struct
{
char inv_num [16];
char prod_name [21];
char prod_code [4];
int oh_qty;
int bo_qty;
int oo_qty;
float inv_eval;
float avg_cost;
float sell_price;
};
struct key
{
char invnbr [16];
int recnbr;
};
key *keyptr = new key[16];
key tempkey;
class inventory
{
protected:
public:
fstream file;
inventory() : file("inventory.dat", ios::out | ios::in | ios::binary)
{
int n, j, k;
bool exchangeMade;
char temp;
k = 0;
exchangeMade = true;
file.seekg(0, ios::end);
n = file.tellg()/sizeof(info);
file.seekg(0, ios::beg);
while ((k < n - 1) && exchangeMade)
{
char temp[16];
exchangeMade = false;
++k;
for (j = 0; j < n - k; ++j)
if (strcmp(info.inv_num[j], info.inv_num[j+1]) > 0)
{
temp = info.inv_num[j];
info.inv_num[j] = info.inv_num[j + 1];
info.inv_num[j + 1] = temp;
exchangeMade = true;
}
}
/* while ((k < n - 1) && exchangeMade)
{
exchangeMade = false;
++k;
for (j = 0; j < n - k; ++j)
if (strcmp(keyptr[j].invnbr, keyptr[j + 1].invnbr) > 0)
{
tempkey = keyptr[j];
keyptr[j] = keyptr[j + 1];
keyptr[j + 1] = tempkey;
exchangeMade = true;
}
}
*/
}
~inventory()
{
file.close(); // Deconstructor
}
};
int main()
{
inventory go;
info x;
string valid;
string neg;
int num_recs;
return 0;
}
Thank you soooo much!!!