Thread: Updating display on screen?

  1. #1
    Registered User
    Join Date
    May 2008

    Updating display on screen?

    I wrote a simple program to print a grid of 0s on the screen, and move a 1 around with user input from the keyboard (eventually, the goal is a "snake" game).

    It works fine. I hit W, it moves the 1 up one space. I hit A, it moves it to the left, etc.

    The problem I'm having is that each time it prints a whole new box. I would much rather have it update the same box each time I hit a key, and I have no idea how to do that.

    I'm currently using this to print my box each time I update the location of my 1:

    How would I make it draw the box only once, and simply update "pixels" in the array as I enter input?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    Use printf("%d\r", ...) to print on the same line. Note that you may have to use fflush(stdout) to make sure the data is ACTUALLY printed.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User guesst's Avatar
    Join Date
    Feb 2008
    Lehi, UT
    Curses. PDCurses for windows.

    Okay, a little more robust of an answer is "cursor control (pixels as you erroniously call them) is not a part of the standard C library and requires external library support." Curses is a standardized library that you can use to acomplish what you're looking for.

    And it just so happens that I've written a little tutorial for setting up PDCurses if you have Code::Blocks.
    Type-ins are back! Visit Cymon's Games at for a new game every week!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. output display in screen required
    By imagetvr in forum C++ Programming
    Replies: 9
    Last Post: 08-19-2008, 09:55 PM
  2. Screen Stream Display Problem
    By mindtrap in forum C# Programming
    Replies: 0
    Last Post: 05-02-2008, 06:54 AM
  3. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 04:56 PM
  4. Replies: 2
    Last Post: 12-29-2005, 04:01 PM
  5. Flash display in DOS screen
    By lordkrishna in forum C++ Programming
    Replies: 9
    Last Post: 02-23-2004, 03:10 AM