473,503 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The program/ header file contents

Karl this is albeit your program, in the program that you wrote for me
I learned quite alot, i didn't realise I could return NULL for
instance or even use functions without first declaring them, but this
is where I'm encountering resistance, as all the bool functions are
compiling with the error: local function definitions are illegal. I've
never used using namespace std before and was wondering if you had
created a header file in conjunction with the program you wrote. Your
program executed perfectly.
Any one else who has spotted something amiss please post back.

Thank you for your kind attention in this matter.


#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <cstdlib>

using namespace std;

struct crecord {
long customercode;
char customername[21];
char customeraddress[61];
double customerbalance;
double creditlimit;
};

struct irrecord {
long customercode;
long partnum;
long issue_rec;
};

struct drecord {
long customercode;
};

////////////////////////////////////////////////////////////
bool IRRecordvalidlength(char* record)
{
int len;

switch(record[0])
{
case'i':
case'I':
case'r':
case'R':
len= strlen(record);
if(len<17)
return false;
break;
}

return true;
};
////////////////////////////////////////////////////////////
bool CRecordvalidlength(ofstream& prnfile, char* cstring)
{
int len;

switch(cstring[0])
{
case'c':
case'C':
len = strlen(cstring);
if(len<103){
prnfile<< "Invalid:";
prnfile<< cstring << endl;

return false;
};

return true;
};
////////////////////////////////////////////////////////
bool Drecordvalidlength(ofstream& prnfile, char* dstring)
{
int len;

switch(dstring)
{
case'd':
case'D':
len = strlen(dstring);
if(len<7){
prnfile<< "Invalid:";
prnfile<< dstring <<endl;
};
return false;

};

return true;
};
//////////////////////////////////////////////////////////
bool CheckAllNumeric( const char * string )
{
int Len = strlen( string );

for( int i = 0; i < Len; ++i )
if( !isdigit( string[i] ) )
return false;

return true;
}

////////////////////////////////////////////////////////////////
bool CheckFloatNumber( const char* string )
{
int Len = strlen( string );

for( int i = 0; i < Len; ++i )
if( !isdigit( string[i] ) &&
string[i] != '.' )
return false;

return true;
}

////////////////////////////////////////////////////////////////

bool Processcrecord( ofstream& prnfile, char* Record )
{
char code[6];
char balance[10];
char limit[10];

crecord Newcrecord;

//
// process the customer code
//
strncpy( code, &record[2], 5 );
code[5] = '\0';
if( !CheckAllNumeric( customercode ) ) {
prnfile << "Invalid: customer code needs to be all numeric
[position 3 - 5 characters]:\n";
prnfile << record << endl;
return false;
}
Newcrecord.customercode = atol( customercode );

//
// process the customer name
//
strncpy( Newcrecord.customername, &record[7], 20 );
Newcrecord.customername[20] = '\0';

//
// process the customer address
//
strncpy( Newcrecord.address, &record[27], 60 );
Newcrecord.address[60] = '\0';

//
// process the customer balance
//
strncpy( balance, &record[87], 9 );
balance[9] = '\0';
if( !CheckFloatNumber( balance ) ) {
prnfile << "Invalid: balance field is not a valid number [position
88 - 9 characters]:\n";
prnfile << record << endl;
return false;
}
Newcrecord.customerbalance = atof( balance );

//
// process the customer limit
//
strncpy( limit, &record[97], 9 );
limit[9] = '\0';
if( !CheckFloatNumber( limit ) ) {
prnfile << "Invalid: limit field is not a valid number [position
98 - 9 characters]:\n";
prnfile << record << endl;
return false;
}
Newcrecord.creditlimit = atof( limit );

return true;

};

///////////////////////////////////////////////////////

bool processdrecord(ofstream& prnfile, char* dstring)
{
char code[6];

strncpy( code, &dstring[2], 5);
code[6] = '\0';
if(!CheckAllNumeric(customercode)){
prnfile<< "Invalid: D record customer code does not contain
numerical format"<<endl;
prnfile<< dstring <<endl;
return false;
};
NewDrecord.customercode = atol( code );

return true;
};
bool ProcessIRecord( ofstream& prnfile, char* record )
{
char customer[6];
char issue_rec[5];
char code[4];
char part[7];

long customer_code;
long part_number;
long issuerec;

//
// process the customer code
//
strncpy( customer, &record[2], 5 );
customer[5] = '\0';
if( !CheckAllNumeric( customer ) ) {
prnfile << "Invalid: customer code needs to be all numeric
[position 3 - 5 characters]:\n";
prnfile << record << endl;
return false;
}
customer_code = atol( customer );

//
// process the part number
//
strncpy( part, &record[7], 6 );
part[6] = '\0';
if( !CheckAllNumeric( part ) ) {
prnfile << "Invalid: part number needs to be all numeric [position
9 - 6 characters]:\n";
prnfile << record << endl;
return false;
}
part_number = atol( part );

//
// process the third number
//
strncpy( issuerec, &Record[13], 4 );
code[4] = '\0';
if( !CheckAllNumeric( issue_rec ) ) {
prnfile << "Invalid: the code needs to be all numeric [position 16
- 4 characters]:\n";
prnfile << Record << endl;
return false;
}
issuerec = atol( issue_rec );
return true;
};

int CheckDigit(long part_number[6], char* record)
{
char partn;
int weightingfactor;
int remainder;
int weightitem1, weightitem2, weightitem3, weightitem4, weightitem5;
int product;
int Mod11 = 11;

strncpy(partn, &record[7], 6);
partn = '\0';
part_number = atol( partn );

weightingfactor = 6;

weightitem1 = (part_number[1] * weightingfactor);

weightingfactor = 5;

weightitem2 = (part_number[2] * weightingfactor);

weightingfactor = 4;

weightitem3 = (part_number[3] * weightingfactor);

weightingfactor = 3;

weightitem4 = (part_number[4] * weightingfactor);

weightingfactor = 2;

weightitem5 = (part_number[5] * weightingfactor);
product = (weightitem1 + weightitem2 + weightitem3 + weightitem4 +
weightitem5);

remainder = (product % Mod11);

checkdigit = (Mod11 - remainder);// may need an if statement
return checkdigit;

};

bool ProcessPartNumber(ofstream& prnfile, char* record)
{
char processpartnum;
long partnumber1[6];

strncpy(processpartnum, &record[7], 6);
processpartnum = '\0';

if( !CheckDigit( processpartnum) ){
prnfile<< "Invalid: Part number does not contain correct check
digit";
prnfile << record << endl;
return false;
};
partnumber1 = atol( processpartnum );

return true;
};

int CheckDigitForCustomerCode(long customer_code[5], char* record)
{
int weightfactor;
int counter1, counter2, counter3, counter4;
int remainder;
int prod;
char custcode;
int Mod11 = 11;
int check_digit;

strncpy(custcode, &record[2], 5);
custcode = '\0';
customer_code[5] = atol( custcode );

weightfactor = 5;

counter1 = (customer_code[1] * weightfactor);

weightfactor = 4;

counter2 = (customer_code[2] * weightfactor);

weightfactor = 3;

counter3 = (customer_code[3] * weightfactor);

weightfactor = 2;

counter4 = (customer_code[4] * weightfactor);

prod = (counter1 + counter2 + counter3 + counter4);

remainder = (prod % Mod11);

check_digit = (Mod11 - remainder);
return check_digit

};

bool ProcessCCustomerCode(ofstream& prnfile, char* record)
{
char check_code;
long checkcode;

strncpy(check_code, &record[2], 5);
check_code = '\0';
if( !CheckDigitForCustomerCode( check_code ){
prnfile<< "Invalid: Incorrect c record customer code, invalid check
digit";
prnfile<< record <<endl;
return false;
};

checkcode = atol (check_code);

return true;

};

bool ProcessDCustomerCode(ofstream& prnfile, char* dstring)
{
char dcustomercode;
long d_code;

strncpy(dcustomercode, &dstring[2], 5);
dcustomercode = '\0';
if( !CheckDigitForCustomerCode ( dcode ) {
prnfile<< "Invalid: Incorrect d record customer code, invalid check
digit";
prnfile<< dstring <<endl;
return false;
};

d_code = atol( dcustomercode );

return true;

};

bool ProcessIRCustomerCode(ofstream& prnfile, char* record)
{
char ircode;
irrecord Newirrecord;

strncpy(ircode, &record[2], 5);
ircode = '\0';
if( !CheckDigitForCustomerCode( ircode ) {
prnfile<< "Invalid: incorrect ir record customer code, invalid check
digit";
prnfile<< record << endl;
return false;
};

Newirrecord.customercode = atol ( ircode );

return true;

};

int main()
{
const char infile[] = "A:\\514650TD.txt";
const char outfile[] = "A:\\514650VD.DAT";
const char printerfile[] = "A:\\514650TD.TXT";

char temp1[104];

ifstream testdata;
ofstream validdata;
ofstream prnfile;

testdata.open(testdata, ios::in);
if(!testdata.fail())
{
cout<<"The file does not already exist";
return EXIT_FAILURE;
}
else
{
cout<<"514650TD is open";
};
validdata.open(validdata, ios::out || ios::binary);
if(!validdata.is_open())
{
cout<<" The file could not be opened "<<endl;;
return EXIT_FAILURE;
}
else
{
cout<<" 514650VD is open "<<endl;
};

prnfile.open(printerfile, ios::out || ios::binary);
if(!prnfile.is_open())
{
cout<< "File could not be opened";
return EXIT_FAILURE;
};

prnfile << "C_RECORD, I-R RECORD, D_RECORD ERRORS" << endl;

while( testdata.getline( temp1, sizeof(temp1)))
{
if(!CRecordvalidlength( temp1 )){
prnfile<<"Invalid: record does not contain enough characters:\n";
prnfile<< temp1 <<endl;
continue;
};

switch( temp1[0] )
{
case 'c':
case 'C':
Processcrecord( prnfile, temp1 );
break;

case 'i':
case 'I':
case 'r':
case 'R':
ProcessIRecord( prnfile, temp1 );
break;

case 'd':
case 'D':
processdrecord( prnfile, temp1 );

};
testdata.close();
validdata.close();
prnfile.close();

};
return EXIT_SUCCESS;

};
Jul 19 '05 #1
2 2891


muser wrote:

Karl this is albeit your program, in the program that you wrote for me
I learned quite alot, i didn't realise I could return NULL for
instance or even use functions without first declaring them,
You can't :-)
but this
is where I'm encountering resistance, as all the bool functions are
compiling with the error: local function definitions are illegal.
A strong indication that you have messed up your { - } pairs somewhere.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <cstdlib>

using namespace std;

struct crecord {
long customercode;
char customername[21];
char customeraddress[61];
double customerbalance;
double creditlimit;
};

struct irrecord {
long customercode;
long partnum;
long issue_rec;
};

struct drecord {
long customercode;
};

////////////////////////////////////////////////////////////
bool IRRecordvalidlength(char* record)
{
int len;

switch(record[0])
{
case'i':
case'I':
case'r':
case'R':
len= strlen(record);
if(len<17)
return false;
break;
}

return true;
};
The ';' is superfluous. Remove it.
////////////////////////////////////////////////////////////
bool CRecordvalidlength(ofstream& prnfile, char* cstring)
{
int len;

switch(cstring[0])
{
case'c':
case'C':
len = strlen(cstring);
if(len<103){
prnfile<< "Invalid:";
prnfile<< cstring << endl;

return false;
};
where is the opening '{' for this '}'
Searching the source backwards, here it is:
if(len<103){
even though the indentation level suggests, that you wanted
to match this } with the one in
switch(cstring[0])
{


But the compiler doesn't care about indentation :-)
The compiler only cares about the stream of tokens.
And the stream of tokens indicate that this '}'
matches the '{' in the if( len<103){
.....
Same thing in a lot of other places.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #2
ch**********@hotmail.com (muser) wrote in message news:<f9**************************@posting.google. com>...
Karl this is albeit your program, in the program that you wrote for me
I learned quite alot, i didn't realise I could return NULL for
instance or even use functions without first declaring them, but this
is where I'm encountering resistance, as all the bool functions are
compiling with the error: local function definitions are illegal. I've
never used using namespace std before and was wondering if you had
created a header file in conjunction with the program you wrote. Your
program executed perfectly.
Any one else who has spotted something amiss please post back.

Thank you for your kind attention in this matter.
You sound like you are continuing a discussion from a previous thread
- I haven't seen the previous thread.

<snip to the cause of your "local function definitions" error>
////////////////////////////////////////////////////////////
bool CRecordvalidlength(ofstream& prnfile, char* cstring)
{
int len;

switch(cstring[0])
{
case'c':
case'C':
len = strlen(cstring);
if(len<103){ Opening brace ^

[Sorry if the indenting has gone wrong here, I have replaced your tabs
with spaces to (hopefully) ensure the ^ symbol lines up where I want
it.]
prnfile<< "Invalid:";
prnfile<< cstring << endl;
No closing brace here where I presume from your indenting you intended
one.

return false;
};
This closing brace ends the if(len<103) block.

return true;
};
This closing brace ends the switch(cstring[0]) block. ie we are still
in the CRecordvalidlength function, and the next thing that happens is
....
////////////////////////////////////////////////////////
bool Drecordvalidlength(ofstream& prnfile, char* dstring)
{
.... a function definition, which is not allowed inside another
function. All the function definitions below are still local to the
CRecordvalidlength function hence illegal. Put in a closing brace for
the if(len<103) block and that problem is fixed.

<snip to the other problem my compiler picked up immediately>
bool ProcessCCustomerCode(ofstream& prnfile, char* record)
{
char check_code;
long checkcode;

strncpy(check_code, &record[2], 5);
check_code = '\0';
if( !CheckDigitForCustomerCode( check_code ){


You're missing a closing parenthesis, you need
if( !CheckDigitForCustomerCode( check_code ) ){
^
[tabs replaced with spaces again]

The identical mistake (cut-and-paste gremlins?) is in
ProcessDCustomerCode and ProcessIRCustomerCode.

<snip the rest of your code>

Having made those changes, I still get lots of errors (42 in fact, how
nice) but without the context of the discussion that led you to this
point, I don't know which you might need help with.

hth
GJD
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1879
by: Marcus | last post by:
Hello, I am having problems with an include statement. I'm setting a session variable flag and then including a file, and in that include file I have a check at the top to make sure that the...
6
2999
by: Juho Saarikko | last post by:
The program attached to this message makes the Python interpreter segfault randomly. I have tried both Python 2.2 which came with Debian Stable, and self-compiled Python 2.3.3 (newest I could find...
6
1733
by: Johannes Bauer | last post by:
Hi group, I've got a question concerning inclusion of .hpp files. Currently I'm including all needed header files in the .cpp file. This means all dependencies of the package and all...
18
2221
by: Exits Funnel | last post by:
Hello, I'm a little confused about where I should include header files and was wondering whether there was some convention. Imagine I've written a class foo and put the definition in foo.h and...
18
2723
by: John Smith | last post by:
Hi all What does the group think of the practise of including one header file from inside another? I have some legacy code where this has been done, and it creates a dependency on a module...
1
3350
by: sangith | last post by:
Hi, I tried the packet capture module program. I did a file transfer using ftp from this host to another server. But when I ran the program, it was just hanging off and it did not print the...
0
1702
by: abarun22 | last post by:
Hi I am facing a problem while including a C header file in the SWIG interface file. However the problem does not occur when i directly copy the contents of header file in the same place. My...
9
1909
by: xiao | last post by:
It always dumped when I tried to run it... But it compiles OK. What I want to do is to do a test: Read information from a .dat file and then write it to another file. The original DAT file is...
1
5985
by: jerry | last post by:
i have written a simple phonebook program,i'll show you some of the codes,the program's head file is member.h . i suppose the head file works well.so i don't post it. here's the clips of main...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7460
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.