TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ALEX WALKER
from: KURT KUZBA
date: 1997-11-05 23:14:00
subject: How to rewrite to screen?

AW>   I'd like to know how you would write and rewrite to screen
AW>   in the same location a number, (or anything really).  For
AW>   example, often with a file search program on BBSs while a
AW>   search is proceding some little wheel thing goes around in
AW>   the same screen prosition like the arms of a clock.  Or
AW>   like an LED display.  But you can't seem to do that with
AW>   the usual cout calls.  How's it done?  Any example C++ code
AW>   I could see?
   If you are referring to console access, as opposed to the use
   of stdout, then it depends a lot on your compiler and OS.
   If you just want to do simple cout stuff, check this:
#include 
#include 
#include 
#include 
#include 
void Spinner(char *pszS)
{
   int iLen = strlen(pszS), iChar = 0;
   clock_t clkDelay;
   while(!kbhit())
   {
      cout << char(pszS[iChar]) << '\b' << flush;
      clkDelay = clock() + (CLOCKS_PER_SEC / 5);
      while(clkDelay > clock())
      ;
      iChar = (iChar + 1) % iLen;
   }
   while(kbhit())
      getch();
   cout << char(pszS[iChar]) << flush;
}
void StaticPrint(unsigned long luN)
{
   char szNum[32];
   int iLen = sprintf(szNum, "%lu", luN);
   cout << szNum;
   while(iLen--)
      cout << '\b';
   cout << flush;
}
void StaticPrint(long lN)
{
   char szNum[32];
   int iLen = sprintf(szNum, "%ld", lN);
   cout << szNum;
   while(iLen--)
      cout << '\b';
   cout << flush;
}
int main(void)
{
   unsigned long luSeconds = 0;
   clock_t clkSeconds;
   cout << "Examples of printing in place" << endl;
   Spinner("/-\|");
   Spinner("O(| |)");
   Spinner("-=~^~=");
   do {
      clkSeconds = clock() + CLOCKS_PER_SEC;
      StaticPrint(luSeconds++);
      while(clkSeconds > clock())
      ;
   }  while(!kbhit());
   while(kbhit())
      getch();
    cout << endl;
   do {
      StaticPrint(clock());
   }  while(!kbhit());
   while(kbhit())
      getch();
   cout << endl;
   return 0;
}
> ] Sorry.  I left my taglines in my other offline reader.......
---
---------------
* Origin: *YOPS ]I[* 3.1 GIG * RA/FD/FE RADist * Milwaukee, WI (1:154/750)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.