muser said:
Victor there is no need to be pedantic,
Yes there is!
programming is all about beeing pedantic!
I realise I could forfeit the
use of arrays and just have a char variable hold the numerical digits,
but these numerical digits require validation as they are part of an
address, i.e. struct records{
first of all (and looking at your program) you need to ditinguish between
* how is the data represented at the file
* how is the data represented in memory
struct file1 {
char record_type;
char customer_name[21];
long customer_code[5];
Here are you sure, that one customer has
5 codes, each one beeing a number
No!
A customer has only one code. At the file level
this code consists of 5 digits (=5 characters),
but once those 5 digits (5 charcaters have been)
read and verified, those 5 digits form a *single*
number:
long customer_code;
char customer_address[61];
long customer_balance[9];
same here:
on the file, the balance takes up 9 characters. But in
the program, those 9 charcaters form a single number.
One number, not 9!
You seem to be under the impression, that
long customer_balance[9];
declares a number which has 9 digits. This is not true!
It declares 9 variables customer_balance, each one of them
beeing able to hold a complete long number.
same here.
It seems to me, you are trying to much for your ability.
And it also seems that either:
* your tutors are nuts
* you don't ask the right questions to them, and they
are unable to understand what you really want or where
your problem really is.
Given your performance in this group, I personally guess it
is the later one.
struct file2 {
char record_type;
long customer_code[5];
long part_num[7];
long issue_rec[4];
};
struct file3 {
char record_type;
long customer_code[5];
};
[snip]
int main()
{ [snip]
char temp_customer_code[5]; [snip]
files.rec1.customer_code[5] = '\0';
files.recl.customer_code is defined to have a length of 5.
Since arrays start with index 0 in C and C++, there is no array
element with index 5. Valid array indices run from 0 to 4.
[snip]
switch(temp_customer_code[5])
Same here. There is no index 5 in temp_customer_code.
{
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '0':
default: prnfile<< "Customer code is invalid, no numerical format
found";
};
Ever heard of isdigit() ?
The above could correctly be rewritten as:
for( int i = 0; i < 5; ++i ) {
if( !isdigit( temp_customer_code
) )
prnfile << "Customer code is invalid, no numerical format found\n";
}
Heck, there are so many problems in your code, that one doesn't know where
to start correcting them. Worse then that. The whole program is flawed. The
best thing (for us) would be to throw it away and start afresh. The best
thing for you: drop this assignment. It is obviously orders of magnitudes
above your head. Start with something simpler.
PS: All of that sounds harsh. It isn't ment to be. The problem is, that you
have problems in walking, but you want to join the New York marathon. Worse
then that - you ask us the equivalent of: How do I win the NY marathon?
Start by learning how to walk.