By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

function code

P: n/a
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?
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
muser wrote:
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.

Jul 19 '05 #2

P: n/a
muser wrote:
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

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.