Need Help with evaluation
Hello.,
I'm very new in C++, and I have a task to solve.
I have a function:
void cio_display(const char *str, int row, int col, int len){
int i;
cio_move(row, col);
if(len<=0) {
cio_putstr(str);
}
else{
for(i=0;i<len && str[i];i++)
cio_putch(str[i]);
for(;i<len;i++)
cio_putch(' ');
}
here iss what i have done:
void cio_display(const char *str, int row, int col, int len){
int i;
cio_move(row, col);
for( i = 0; ((len <= 0) && cio_putstr(str)), (i < len && str[i]); i++){
cio_putch(str[i]);
}
for(;i<len;i++)
cio_putch(' ');
}
The problem id the function cio_putstr() returns void, thats why lazy evaluation is not possible. Any other thoughts would be greatly appreciated!
Thank you
atman
Junior Poster in Training
50 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
I have no idea what you are talking about. What is "lazy evaluation" ? And why does it matter whether cio_putstr() returns void or something else ?
Ancient Dragon
Retired & Loving It
30,043 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
sorry was in a rush and forgot to ask., The question is how to rewrite the function w/o using if statement.
Any help would be appreciated
atman
Junior Poster in Training
50 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
What's a problem?
for (i = 0;
len <= 0 && str[i] || str[i] && i < len;
i++) {
cio_putch(str[i]);
}
while (i++ < len)
cio_putch(' ');
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
>just why is it in your for loop as a test expression?
That's a good question ;)
However there is an absolutely senseless condition with comma operator in that snippet, so it does not matter why ;)...
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
>[/B] To Ancient Dragon: I read about "lazy evaluation" in some book, but I don't remember which one :( ... Anyway, here is wiki on it.
OMG I've been doing that for 50 years and always thought it was called procrastination. Now I know I was just plain lazy :)
Ancient Dragon
Retired & Loving It
30,043 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
a switch statement??
What's a cool tip!
Which else C++ control statements are you familiar with?
;)
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348