function code

M

muser

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

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

case 'd':
case 'D':
processdrecord( temp1, prnfile, validdata );
break;
default: prnfile<< "Unknown record\n";
prnfile<< temp1 << endl;
};

if(Processcrecord( temp1, prnfile, validdata )){ true; }{
validdata << temp1 << endl;// suppose to check that the function evaluates true
break;// and then writes it to the validdata file.
}
if(ProcessIRecord( temp1, prnfile, validdata )){ true; }{
validdata << temp1 << endl;
break;
}
if(processdrecord( temp1, prnfile, validdata )){ true; }{
validdata << temp1 << endl;
break;
}
does //if(Processcrecord( temp1 etc ) actually perform the task its suppose to?
Is the code correct or does the if statement always return true regardless?
 
R

Rolf Magnus

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

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

case 'd':
case 'D':
processdrecord( temp1, prnfile, validdata );
break;
default: prnfile<< "Unknown record\n";
prnfile<< temp1 << endl;
};

if(Processcrecord( temp1, prnfile, validdata )){ true; }{
validdata << temp1 << endl;// suppose to check that the function
evaluates true break;// and then writes it to the validdata file.
}
if(ProcessIRecord( temp1, prnfile, validdata )){ true; }{
validdata << temp1 << endl;
break;
}
if(processdrecord( temp1, prnfile, validdata )){ true; }{
validdata << temp1 << endl;
break;
}
does //if(Processcrecord( temp1 etc ) actually perform the task its
suppose to?

I don't know. It doesn't seem to make sense. If the condition between
the braces of the if() is true (i.e. if Processcrecord returns
something that evaluates to true), the following code block is
executed. That code block only contains true; which is a statement that
actually doesn't do anything and has (of course) true as result. That
result is discarded. So the whole if() is useless. The code block
following the { true; } one is executed unconditionally. So your:

if(Processcrecord( temp1, prnfile, validdata )){ true; }{
validdata << temp1 << endl;
break;
}

does the same as:

Processcrecord( temp1, prnfile, validdata );
validdata << temp1 << endl;
break;

And btw, what is the break supposed to do? Or is that if() actually
supposed to be within the switch/case?

Is the code correct or does the if statement always return
true regardless?

An if statement doesn't return anything.
 
T

Thomas Matthews

muser said:
switch( temp1[0] )
{
case 'c':
case 'C':
Processcrecord( temp1, prnfile, validdata );
break;
Study the std::tolower and std::toupper functions:
swtich(std::tolower(temp1[0]))
{
case 'c':
case 'i':
case 'I':
case 'r':
case 'R':
ProcessIRecord( temp1, prnfile, validdata );
break;

case 'd':
case 'D':
processdrecord( temp1, prnfile, validdata );
break;
default: prnfile<< "Unknown record\n";
prnfile<< temp1 << endl;
};
does //if(Processcrecord( temp1 etc ) actually perform the task its
suppose to?
Is the code correct or does the if statement always return true regardless?

I suggest you use a different naming convention.
At first look, all the functions looked the same or
the others look like a misspelling of the first.


--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top