J
JasBascom
I thought it was too much to put this program in with my last message. The
program compiles ok, but when I execute, I get access errors.
can someone put it through their compiler please. I think the problem lies
when i declare union Allrecords h1,h2,h3.
and then use them to toupper record_type. the debug when i use it can not go
past the switch statement.
thank you for you help
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <cstdlib>
using namespace std;
struct crecord {
char record_type;
char customercode[6];
char customername[21];
char customeraddress[61];
char customerbalance;
char creditlimit;
};
crecord Newcrecord;
struct irrecord {
char record_type;
char customercode[6];
char partnum[7];
char issue_rec;
};
irrecord Newirrecord;
struct drecord {
char record_type;
char customercode[6];
};
drecord Newdrecord;
union Allrecords {
struct crecord Newcrecord;
struct irrecord Newirrecord;
struct drecord Newdrecord;
};
const int list = 200;
int loop = 200;
union Allrecords records
program compiles ok, but when I execute, I get access errors.
can someone put it through their compiler please. I think the problem lies
when i declare union Allrecords h1,h2,h3.
and then use them to toupper record_type. the debug when i use it can not go
past the switch statement.
thank you for you help
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <cstdlib>
using namespace std;
struct crecord {
char record_type;
char customercode[6];
char customername[21];
char customeraddress[61];
char customerbalance;
char creditlimit;
};
crecord Newcrecord;
struct irrecord {
char record_type;
char customercode[6];
char partnum[7];
char issue_rec;
};
irrecord Newirrecord;
struct drecord {
char record_type;
char customercode[6];
};
drecord Newdrecord;
union Allrecords {
struct crecord Newcrecord;
struct irrecord Newirrecord;
struct drecord Newdrecord;
};
const int list = 200;
int loop = 200;
union Allrecords records
- ;
union Allrecords *rec = records;
void sort_function( union Allrecords *rec, ifstream& validdata )
{
union Allrecords *str_ptr1 = rec;
union Allrecords *str_ptr2, tempstr;
for(int i =0; i< loop; i++)
while( strcmp(str_ptr1.Newcrecord.customercode, '\0') ||
strcmp(str_ptr1.Newdrecord.customercode, '\0') ||
strcmp(str_ptr1.Newirrecord.customercode, '\0'))
{
str_ptr2 = str_ptr1 + 1;//set to next element.
for( i=0; i<loop; i++)
while( strcmp(str_ptr2.Newcrecord.customercode, '\0') ||
strcmp(str_ptr2.Newdrecord.customercode, '\0'))
{
for(int i=0; i<loop; i++)
if( strcmp( str_ptr1.Newirrecord.customercode,
str_ptr2.Newirrecord.customercode + 1))
{
tempstr = *str_ptr1;
*str_ptr1 = *str_ptr2;
*str_ptr2 = tempstr;
}
*str_ptr1++;//incremented, so that the same code isn't sorted again
}
str_ptr2++;
}
}
int main()
{
union Allrecords h1, h2, h3;
h1.Newcrecord.record_type = 'c';
h1.Newcrecord.record_type = toupper(Newcrecord.record_type);
h2.Newirrecord.record_type = 'i' | 'r';
h2.Newirrecord.record_type = toupper(Newirrecord.record_type);
h3.Newdrecord.record_type = 'd';
h3.Newdrecord.record_type = toupper(Newdrecord.record_type);
const char outfile[] = "A:\\514650VDP1.bin";
const char infile[] = "A:\\514650SD.txt";
long offset = 0;
int filesize;
int reccount;
ifstream validdata;
fstream sortfile;
validdata.open("A:\\514650VDP1.bin", ios::in | ios::binary);
if(!validdata)
{
cout<< " Unable to open file" <<endl;
exit(1);
};
sortfile.open("A:\\514650SD.txt", ios:ut);
if(!sortfile)
{
cout<< "Cannot create file" << endl;
exit(1);
};
validdata.seekg(0, ios::end);
filesize = validdata.tellg();
validdata.seekg(offset, ios::beg);
reccount = filesize/sizeof(Allrecords);
rec = new(Allrecords[reccount]);
validdata.read((char*) &rec, filesize);
for(int i = 0; i <reccount; i++)
{
switch(rec.Newdrecord.record_type)
{
case 'c':
case 'C':
case 'd':
case 'D':
case 'i':
case 'I':
case 'r':
case 'R':
sort_function1();
default:;
};
};
validdata.close();
sortfile.close();
return 0;
};