Need Help with evaluation

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2008
Posts: 48
Reputation: atman is an unknown quantity at this point 
Solved Threads: 0
atman atman is offline Offline
Light Poster

Need Help with evaluation

 
0
  #1
May 23rd, 2009
Hello.,
I'm very new in C++, and I have a task to solve.
I have a function:

  1. void cio_display(const char *str, int row, int col, int len){
  2. int i;
  3. cio_move(row, col);
  4. if(len<=0) {
  5. cio_putstr(str);
  6. }
  7. else{
  8. for(i=0;i<len && str[i];i++)
  9. cio_putch(str[i]);
  10.  
  11. for(;i<len;i++)
  12. cio_putch(' ');
  13. }

here iss what i have done:

  1. void cio_display(const char *str, int row, int col, int len){
  2.  
  3. int i;
  4. cio_move(row, col);
  5. for( i = 0; ((len <= 0) && cio_putstr(str)), (i < len && str[i]); i++){
  6. cio_putch(str[i]);
  7. }
  8.  
  9. for(;i<len;i++)
  10. cio_putch(' ');
  11. }

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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,679
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1504
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Need Help with evaluation

 
0
  #2
May 23rd, 2009
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 ?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 48
Reputation: atman is an unknown quantity at this point 
Solved Threads: 0
atman atman is offline Offline
Light Poster

Sorry, was in the rush and forgot to ask...

 
0
  #3
May 24th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 128
Reputation: kenji is an unknown quantity at this point 
Solved Threads: 10
kenji's Avatar
kenji kenji is offline Offline
Junior Poster

Re: Need Help with evaluation

 
0
  #4
May 24th, 2009
Um..."while" and "for" come to mind, just need to use a little creativity. Its not that hard.
And she said "Let there be light" and on the seveth day Windows booted.
And the crowds screamed in terror and cowered in fear for Microsoft had approached.
From the testament of 10011101
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Need Help with evaluation

 
0
  #5
May 24th, 2009
What's a problem?
  1. for (i = 0;
  2. len <= 0 && str[i] || str[i] && i < len;
  3. i++) {
  4. cio_putch(str[i]);
  5. }
  6. while (i++ < len)
  7. cio_putch(' ');
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 155
Reputation: amrith92 is on a distinguished road 
Solved Threads: 18
amrith92's Avatar
amrith92 amrith92 is offline Offline
Junior Poster

Re: Need Help with evaluation

 
0
  #6
May 24th, 2009
> To the OP: You say that this function - cio_putstr() returns a void . If this is so, then just why is it in your for loop as a test expression? And could you explain what it - cio_putstr() - is supposed to do?

> To Ancient Dragon: I read about "lazy evaluation" in some book, but I don't remember which one ... Anyway, here is wiki on it.
Last edited by amrith92; May 24th, 2009 at 6:37 am.
"C++ : Where friends have access to your private members."
C++: You accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical assistance is impossible since you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there."
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Need Help with evaluation

 
0
  #7
May 24th, 2009
>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 ...
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,679
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1504
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Need Help with evaluation

 
0
  #8
May 24th, 2009
Originally Posted by amrith92;874959[B
>[/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
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 8
Reputation: jloundy has a little shameless behaviour in the past 
Solved Threads: 0
jloundy jloundy is offline Offline
Newbie Poster

Re: Need Help with evaluation

 
0
  #9
May 27th, 2009
a switch statement??
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Need Help with evaluation

 
0
  #10
May 28th, 2009
Originally Posted by jloundy View Post
a switch statement??
What's a cool tip!
Which else C++ control statements are you familiar with?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum


Views: 333 | Replies: 9
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC