Teen Programmers Unite  
 

 

Return to forum top

Replacing a character at run time.

Posted by split [send private reply] at November 30, 2002, 06:34:32 PM

Hi everyone, great site you have here.

I was wondering how I could make a spinning figure in the console (hard to explain maybe, but I want a figure that changes from | to / to - to \ to | to / to - to / to |)
What I am doing right now is something like this:
cout << "|";
Sleep(100); //windows.h Sleep function
system("cls");

I do that for each symbol. It works fine but the problem is that it requires the screen be cleared each time.

When I booted Linux today I noticed that when checking the filesystem it had a spinning thing going constantly without clearing the screen. How would this be done? A loop that replaces the character each time?
I am probably missing something very basic and any help would be appreciated. Thanks -split-

Posted by regretfuldaydreamer [send private reply] at November 30, 2002, 06:37:40 PM

Is there no C locate function (like in Basic)

Posted by unknown_lamer [send private reply] at November 30, 2002, 08:34:39 PM

You can print the the delete character to the screen, e.g.

int main (int argc, char **argv)
{
  printf ("\\");
  fflush (stdout);
  sleep (1);
  printf ("\b-");
  fflush (stdout);
  sleep (1);
  fflush (stdout);
  printf ("\b/");
  return 0;
}


Flushing the output device is important, otherwise you probably won't see anything but the last character because I/O is generally line buffered (i.e. the line isn't actually printed until a newline is printed).
Posted by split [send private reply] at December 02, 2002, 06:34:06 AM

Yes, looks perfect. I didn't even think of using \b. Thanks for the help.

Posted by Hardlaugh_ [send private reply] at December 04, 2002, 02:56:58 AM

Another solution of course, assuming You're running on normal PC hardware, would be to mmap the memory at B8000h, which is the text display. :)

Posted by Psion [send private reply] at December 04, 2002, 06:12:03 AM

Hopefully your OS disallows that.

Posted by DragonWolf [send private reply] at December 05, 2002, 05:22:15 AM

Can't you also simply change the character at coordinate x,y on the screen? Thats what I used to do with QBasic, I've never tried it in C.

Posted by buzgub [send private reply] at December 05, 2002, 06:29:23 AM

Dragonwolf, not portably. If you can do it, it's not part of the standard.

Posted by DragonWolf [send private reply] at December 05, 2002, 08:55:54 AM

This WAS QBasic ^^ When I was doing QBasic (8-10 years ago), as far as I know it only ran in DOS.

I don't see how this causes a portability problem though (depending on how you go about it)

Posted by RedX [send private reply] at December 05, 2002, 12:53:24 PM

Qbasic runs fine under win'98.

Posted by regretfuldaydreamer [send private reply] at December 05, 2002, 01:18:12 PM

Theres no locate type function as part of the C-standard, so if a function like that did exist in one implementation, it wouldn't be portable.

Posted by Hardlaugh_ [send private reply] at December 06, 2002, 11:20:16 AM

Might be off-topic (but this topic got out of hand anyway, so), but did you know that there was actually a Visual Basic for DOS? :)) It compiles almost all QBASIC code and has a forms-based interface like VB/Win, only that it's in DOS text mode. Hahaha. If You're in for some fun, just search for vbdos.zip or something and You'll be able to find it quickly.

Posted by Neumann [send private reply] at December 06, 2002, 11:37:47 AM

COOOOOOOOOOOOOOL!!

I didn't expect to see Visual Basic for DOS in my life!

Posted by regretfuldaydreamer [send private reply] at December 06, 2002, 04:41:51 PM

Yeah theres Visual Basic 2 for DOS

I have a book on it - Or a chapter within a good big massive book on Dos.

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.