473,473 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

passing a parameter

How can I pass the parameter " long part_num[6], into a case
statement. Case statement follows the function CheckDigit.

i.e. CheckDigit( something, temp1 );

Thank you for your help in advance.
bool CheckDigit(long part_num[6], char* record)
{

int weightingfactor;
int remainder;
int weightitem1, weightitem2, weightitem3, weightitem4, weightitem5;
int product;
int Mod11 = 11;
int checkdigit;
char partnum[6];


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

weightingfactor = 6;

weightitem1 = (part_num[1] * weightingfactor);

weightingfactor = 5;

weightitem2 = (part_num[2] * weightingfactor);

weightingfactor = 4;

weightitem3 = (part_num[3] * weightingfactor);

weightingfactor = 3;

weightitem4 = (part_num[4] * weightingfactor);

weightingfactor = 2;

weightitem5 = (part_num[5] * weightingfactor);


product = (weightitem1 + weightitem2 + weightitem3 + weightitem4 +
weightitem5);

remainder = (product % Mod11);

checkdigit = (Mod11 - remainder);
if(!part_num[6] == checkdigit)
return false;
return true;

} case 'i':
case 'I':
case 'r':
case 'R':
ProcessIRecord( prnfile, temp1 );
CheckDigit( temp1 );
break;
Jul 19 '05 #1
2 1985
muser wrote:
How can I pass the parameter " long part_num[6], into a case
statement.
I don't understand that question. You don't pass parameters to "case
statements" (there's really no such thing as a case statement).
Case statement follows the function CheckDigit.

i.e. CheckDigit( something, temp1 );

Thank you for your help in advance.
bool CheckDigit(long part_num[6], char* record)
Please not that you are not, in fact, passing an array to this function.
The type of part_num is actually "long *". Therefore it may be prudent
to also pass in the length of the array pointed to by part_num. The 6 in
this case has no meaning (the compiler ignores it).

Also, prefer std::string to char* for dealing with strings.
{

int weightingfactor;
int remainder;
int weightitem1, weightitem2, weightitem3, weightitem4, weightitem5;
Why not

int weightitem[5];

or

std::vector<int> weightitem(5);

?
int product;
int Mod11 = 11;
Is this really any better than just using the magic number 11? Use a
descriptive name or don't use a name at all.
int checkdigit;
char partnum[6];
Prefer std::string to char arrays when dealing with strings.

strncpy(partnum, &record[7], 6);
Are you quite sure you can index that far into record?
partnum[6] = '\0';
This is illegal. The last valid index for partnum is 5.
part_num[6] = atol( partnum );
If part_num is actually 6 elements long as you suggest, then this is
illegal. The last valid index is 5.

Also, atol is a very unsafe function. strtol would be better. using
strings and streams (istringstream for this conversion) would be better
still. Another good option would be something like boost::lexical_cast
or your own conversion function (using one of the safe methods).
weightingfactor = 6;
weightitem1 = (part_num[1] * weightingfactor);
weightingfactor = 5;
weightitem2 = (part_num[2] * weightingfactor);
weightingfactor = 4;
weightitem3 = (part_num[3] * weightingfactor);
weightingfactor = 3;
weightitem4 = (part_num[4] * weightingfactor);
weightingfactor = 2;
weightitem5 = (part_num[5] * weightingfactor);
OK.... Why did you not use an array or vector, then loop to do this? Or
at least eliminate weightingfactor by multiplying by the magic number
directly.

product = (weightitem1 + weightitem2 + weightitem3 + weightitem4 +
weightitem5);

remainder = (product % Mod11);

checkdigit = (Mod11 - remainder);
if(!part_num[6] == checkdigit)
Another bad index, probably.
return false;
Indent that so people can see it goes with the 'if'. Better yet, enclose
it in {}.


return true;

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


I'm afraid I still don't understand what you are asking. But your
CheckDigit call here is missing a parameter.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #2
muser wrote:
How can I pass the parameter " long part_num[6], into a case
statement. Case statement follows the function CheckDigit.

[SNIP]

You cannot. The switch in C and C++ supports only integer values, not
arrays.

--
WW aka Attila
Jul 19 '05 #3

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

Similar topics

3
by: WGW | last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem... I can...
5
by: Andy | last post by:
Hi Could someone clarify for me the method parameter passing concept? As I understand it, if you pass a variable without the "ref" syntax then it gets passed as a copy. If you pass a...
6
by: wiredless | last post by:
What is the advantage of passing an interface type? according to UML (visio) when i reverse engineer existing code to a UML diagram I get the error "UMLE00046: sample : - An interface cannot...
11
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
2
by: diffuser78 | last post by:
I wrote a small app in wxPython using wxGlade as designer tool. wxGlade brings and writes a lot of code by itself and thats where my confusion started. Its about parameter passing. Here is my...
10
by: amazon | last post by:
Our vender provided us a web service: 1xyztest.xsd file... ------------------------------------ postEvent PostEventRequest ------------------------------------- authetication authentication...
0
by: amazon | last post by:
I have web service that acceping following parameters.. postev.PostEvent(authentication as ws.authentication, name as string,id as string, exdate as date, parameter() as ws.nameparametervaluepair...
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
12
by: dave_dp | last post by:
Hi, I have just started learning C++ language.. I've read much even tried to understand the way standard says but still can't get the grasp of that concept. When parameters are passed/returned...
4
by: Deckarep | last post by:
Hello fellow C# programmers, This question is more about general practice and convention so here goes: I got into a discussion with a co-worker who insisted that as a general practice all...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.