M
muser
sorry to post so soon after having posted before. I'm using a union
and I've read that a union can only hold a value of one member at a
time. The following function uses a union, but i don't know whether
the errors I'm getting is because of that, or because i have declared
the union instances wrong, can you please help.
struct crecord {
char customercode[5];
char customername[21];
char customeraddress[61];
char customerbalance;
char creditlimit;
int Totalbalance;
int Totalcreditlimit;
};
struct irrecord {
char customercode[5];
char partnum[6];
char issue_rec[5];
};
struct drecord {
char customercode[5];
};
int loop = 200;
union Allrecords{
struct crecord Newcrecord;
struct irrecord Newirrecord;
struct drecord Newdrecord;
};
union Allrecords unionarray;
void determinestruct( union Allrecords unionarray, fstream& validdata,
char* temp2 )
{
union Allrecords *str_ptr1, *str_ptr2;
str_ptr2 = str_ptr1 + 1;
if(validdata.peek(temp2[0]) == 'c' || validdata.peek(temp2[0]) ==
'C')
{
str_ptr1 = str_ptr1.Newcrecord.customercode, '\0';
}
if(validdata.peek(temp2[0]) == 'i' || validdata.peek(temp2[0]) == 'I'
|| validdata.peek(temp2[0]) == 'r' || validdata.peek(temp2[0]) == 'R'
)
{
str_ptr1 = str_ptr1.Newirrecord.customercode, '\0';
}
if(validdata.peek(temp2[0]) == 'd' || validdata.peek(temp2[0]) ==
'D')
{
str_ptr1 = str_ptr1.Newdrecord.customercode, '\0';
}
if(validdata.peek(temp2[0]) == 'c' || validdata.peek(temp2[0]) ==
'C')
{
str_ptr2 = str_ptr2.Newcrecord.customercode, '\0';
}
if(validdata.peek(temp2[0]) == 'i' || validdata.peek(temp2[0]) == 'I'
|| validdata.peek(temp2[0]) == 'r' || validdata.peek(temp2[0]) == 'R'
)
{
str_ptr2 = str_ptr2.Newirrecord.customercode, '\0';
}
if(validdata.peek(temp2[0]) == 'd' || validdata.peek(temp2[0]) ==
'D')
{
str_ptr2 = str_ptr2.Newdrecord.customercode, '\0';
}
}
and I've read that a union can only hold a value of one member at a
time. The following function uses a union, but i don't know whether
the errors I'm getting is because of that, or because i have declared
the union instances wrong, can you please help.
struct crecord {
char customercode[5];
char customername[21];
char customeraddress[61];
char customerbalance;
char creditlimit;
int Totalbalance;
int Totalcreditlimit;
};
struct irrecord {
char customercode[5];
char partnum[6];
char issue_rec[5];
};
struct drecord {
char customercode[5];
};
int loop = 200;
union Allrecords{
struct crecord Newcrecord;
struct irrecord Newirrecord;
struct drecord Newdrecord;
};
union Allrecords unionarray;
void determinestruct( union Allrecords unionarray, fstream& validdata,
char* temp2 )
{
union Allrecords *str_ptr1, *str_ptr2;
str_ptr2 = str_ptr1 + 1;
if(validdata.peek(temp2[0]) == 'c' || validdata.peek(temp2[0]) ==
'C')
{
str_ptr1 = str_ptr1.Newcrecord.customercode, '\0';
}
if(validdata.peek(temp2[0]) == 'i' || validdata.peek(temp2[0]) == 'I'
|| validdata.peek(temp2[0]) == 'r' || validdata.peek(temp2[0]) == 'R'
)
{
str_ptr1 = str_ptr1.Newirrecord.customercode, '\0';
}
if(validdata.peek(temp2[0]) == 'd' || validdata.peek(temp2[0]) ==
'D')
{
str_ptr1 = str_ptr1.Newdrecord.customercode, '\0';
}
if(validdata.peek(temp2[0]) == 'c' || validdata.peek(temp2[0]) ==
'C')
{
str_ptr2 = str_ptr2.Newcrecord.customercode, '\0';
}
if(validdata.peek(temp2[0]) == 'i' || validdata.peek(temp2[0]) == 'I'
|| validdata.peek(temp2[0]) == 'r' || validdata.peek(temp2[0]) == 'R'
)
{
str_ptr2 = str_ptr2.Newirrecord.customercode, '\0';
}
if(validdata.peek(temp2[0]) == 'd' || validdata.peek(temp2[0]) ==
'D')
{
str_ptr2 = str_ptr2.Newdrecord.customercode, '\0';
}
}