GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-Sep-2005, 17:51
Zorachus's Avatar
Zorachus Zorachus is offline
Junior Member
 
Join Date: Jul 2005
Posts: 58
Zorachus will become famous soon enough

clrscr()- Alternatives?


I hate to post something when the answer is probably already on the site, but I've been searching for a while and can't find the answer to this. I wrote a program to calculate the number of seconds left in high school:

CPP / C++ / C Code:
#include <iostream>
#include <ctime>
#include <conio.h>
#include <iomanip>
/////////////////////////////
#define SEPT_SECOND 1125633605
#define TIME_UNTIL_END 22899600
/////////////////////////////
using namespace std;

int main()

{
    int x=2;
    while (x != 1)
    {
          cout << "Smile!  Only " << (SEPT_SECOND+TIME_UNTIL_END)-time('\0') << " seconds of high school left!\n";
          cout << "That's approximately:\n\n" << ((SEPT_SECOND+TIME_UNTIL_END)-time('\0'))/60 << " minutes!\n";
          cout << ((SEPT_SECOND+TIME_UNTIL_END)-time('\0'))/60/60 << " hours!\n";
          cout << ((SEPT_SECOND+TIME_UNTIL_END)-time('\0'))/60/60/24 << " days!\n";
          cout << "\n\n\n\n\n\n\n";
          cout << "Calculated Sept. 1, 2005 for projected time May 26th, 2006, 11:30 a.m.\n";
          cout << "Not accounting for snow days.\n";
          cout << "Seconds are precise.  Minutes, Hours, and Days may be slightly off.\n";
          x++;
          if (x>500)
          x=2;
          system ("cls");
    }
}

and I'm looking for an alternative to
CPP / C++ / C Code:
system ("cls")
. I'm not crazy about this because it's a memory hog, and the program hogs enough memory as it is. (Yes, I've tried using clrscr(), but I'm not using a Borland compiler and my Dev-c++ compiler apparently doesn't recognize the clrscr command (yes, i've included conio.h))

By the way, when I started programming, it was in a 2d game language called Blitz Basic. What I remember from it was that there was a front and back buffer. Instead of writing directly to the front buffer, the current screen was written to the backbuffer, and then the backbuffer was "flipped," causing the frontbuffer to become the backbuffer and vice versa. This eliminated the flickering problem that you see here. Is there a simple way to do this in c++? Thank you.
  #2  
Old 01-Sep-2005, 19:35
Evil Requiem Evil Requiem is offline
New Member
 
Join Date: Aug 2005
Posts: 24
Evil Requiem will become famous soon enough
What the hell ? Flickering in console mode ? That's the first time I hear about that. ??: The only way to use a backbuffer is when you're programming under the GDI Win32 API but I could be wrong..
  #3  
Old 01-Sep-2005, 20:54
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,234
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by Zorachus
I hate to post something when the answer is probably already on the site, but I've been searching for a while and can't find the answer to this.
...
and I'm looking for an alternative to
CPP / C++ / C Code:
system ("cls")
. I'm not crazy about this because it's a memory hog, and the program hogs enough memory as it is. (Yes, I've tried using clrscr(), but I'm not using a Borland compiler and my Dev-c++ compiler apparently doesn't recognize the clrscr command (yes, i've included conio.h))
Nope, there is nothing standard. C/C++ do not do screen control.

Quote:
Originally Posted by Zorachus
By the way, when I started programming, it was in a 2d game language called Blitz Basic. What I remember from it was that there was a front and back buffer. Instead of writing directly to the front buffer, the current screen was written to the backbuffer, and then the backbuffer was "flipped," causing the frontbuffer to become the backbuffer and vice versa. This eliminated the flickering problem that you see here. Is there a simple way to do this in c++? Thank you.
Where do I see this flickering problem?

This sounds like DOS days when you had control over the hardware. Not no more...
__________________

Cow: You're a lawyer too?
Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase!
  #4  
Old 02-Sep-2005, 05:14
Zorachus's Avatar
Zorachus Zorachus is offline
Junior Member
 
Join Date: Jul 2005
Posts: 58
Zorachus will become famous soon enough
The flickering problem is from the screen being updated so many times constantly. But, oh well, it is readable, so I guess it's not that big of a deal. Thanks
__________________
Pursue everything!

P.S. This is what you would get at some point in the alphabet with the removal of the Q and R.
  #5  
Old 02-Sep-2005, 10:19
Zorachus's Avatar
Zorachus Zorachus is offline
Junior Member
 
Join Date: Jul 2005
Posts: 58
Zorachus will become famous soon enough
I just pulled this out of the MSDN database:

CPP / C++ / C Code:
 /* Standard error macro for reporting API errors */
 #define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \
    on line %d\n", __FILE__, GetLastError(), api, __LINE__);}

 void cls( HANDLE hConsole )
 {
    COORD coordScreen = { 0, 0 };    /* here's where we'll home the
                                        cursor */
    BOOL bSuccess;
    DWORD cCharsWritten;
    CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
    DWORD dwConSize;                 /* number of character cells in
                                        the current buffer */

    /* get the number of character cells in the current buffer */

    bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
    PERR( bSuccess, "GetConsoleScreenBufferInfo" );
    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;

    /* fill the entire screen with blanks */

    bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) ' ',
       dwConSize, coordScreen, &cCharsWritten );
    PERR( bSuccess, "FillConsoleOutputCharacter" );

    /* get the current text attribute */

    bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
    PERR( bSuccess, "ConsoleScreenBufferInfo" );

    /* now set the buffer's attributes accordingly */

    bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
       dwConSize, coordScreen, &cCharsWritten );
    PERR( bSuccess, "FillConsoleOutputAttribute" );

    /* put the cursor at (0, 0) */

    bSuccess = SetConsoleCursorPosition( hConsole, coordScreen );
    PERR( bSuccess, "SetConsoleCursorPosition" );
    return;
 }

That is a function to clear the screen. However, in a program this small, it seems like that would be more trouble than it is worth. So I guess it's either Borland or system ("cls") for me. Oh well.
__________________
Pursue everything!

P.S. This is what you would get at some point in the alphabet with the removal of the Q and R.
  #6  
Old 02-Sep-2005, 10:24
L7Sqr L7Sqr is offline
Member
 
Join Date: Jul 2005
Location: constant limbo
Posts: 103
L7Sqr will become famous soon enough
Regarding the memory hog issue...
You might want to implement a sleep function that will wake every half-second or so and update the screen.
Also, rather than continually updating the variable x so much (I'n not really sure why you did that) why not just have a while(1) or for ( ;; ). You could exit (if you ever wanted to) with a break statement.
  #7  
Old 02-Sep-2005, 21:20
Zorachus's Avatar
Zorachus Zorachus is offline
Junior Member
 
Join Date: Jul 2005
Posts: 58
Zorachus will become famous soon enough
I had tried the sleep function already, but that just made it flicker a lot more, for some odd reason (hey, we're not supposed to make sense out of these things, right?).
And as for the weird x loop, that's just because for some reason, the compiler wouldn't let me use while(1). I don't know if it didn't want me to have an infinite loop or what. Anyway, I'll probably just leave it like it is. Thanks though!
__________________
Pursue everything!

P.S. This is what you would get at some point in the alphabet with the removal of the Q and R.
  #8  
Old 03-Sep-2005, 12:46
Zorachus's Avatar
Zorachus Zorachus is offline
Junior Member
 
Join Date: Jul 2005
Posts: 58
Zorachus will become famous soon enough
Well, that's odd. It seems that if I put the Sleep function in one place (and only one place) that it solves both the flickering and memory problem. That's kind of weird, but I don't question it. Thanks.
__________________
Pursue everything!

P.S. This is what you would get at some point in the alphabet with the removal of the Q and R.
 

Recent GIDBlogPrepping for deployment by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing the " underline pointer?" and advance clrscr()? leitz C Programming Language 7 14-Nov-2004 11:53
equivalent of clrscr() on unix/linux?? nkhambal C Programming Language 1 03-Sep-2004 16:53

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:25.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.