943,740 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 495
  • C++ RSS
May 23rd, 2009
0

Need Help with evaluation

Expand Post »
Hello.,
I'm very new in C++, and I have a task to solve.
I have a function:

C++ Syntax (Toggle Plain Text)
  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:

C++ Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
atman is offline Offline
50 posts
since Oct 2008
May 23rd, 2009
0

Re: Need Help with evaluation

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 ?
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
May 24th, 2009
0

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

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
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
atman is offline Offline
50 posts
since Oct 2008
May 24th, 2009
0

Re: Need Help with evaluation

Um..."while" and "for" come to mind, just need to use a little creativity. Its not that hard.
Reputation Points: 11
Solved Threads: 11
Junior Poster
kenji is offline Offline
145 posts
since May 2008
May 24th, 2009
0

Re: Need Help with evaluation

What's a problem?
C++ Syntax (Toggle Plain Text)
  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(' ');
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
May 24th, 2009
0

Re: Need Help with evaluation

> 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.
Reputation Points: 130
Solved Threads: 22
Junior Poster
amrith92 is offline Offline
187 posts
since Jul 2008
May 24th, 2009
0

Re: Need Help with evaluation

>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 ...
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
May 24th, 2009
0

Re: Need Help with evaluation

Quote 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
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
May 27th, 2009
0

Re: Need Help with evaluation

a switch statement??
Reputation Points: 5
Solved Threads: 0
Newbie Poster
jloundy is offline Offline
8 posts
since May 2009
May 28th, 2009
0

Re: Need Help with evaluation

Click to Expand / Collapse  Quote originally posted by jloundy ...
a switch statement??
What's a cool tip!
Which else C++ control statements are you familiar with?
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Problem writing to a binary file
Next Thread in C++ Forum Timeline: need help to solve this problem!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC