Menu

possible solution for clrscr()

2003-01-19
2012-09-26
  • Dinesh Pillay

    Dinesh Pillay - 2003-01-19

    People who want to use clrscr and can't seem to get it work with DevC++ for whatever reason can do this

    1. Create a clrscr.c file

    and add the following code......

    #ifndef _CONIO_C_
    #define _CONIO_C_

    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <windows.h>
    #include <string.h>
    #include "conio.h"

    #ifndef _COLORS_
    #define _COLORS_
    enum COLORS {
        BLACK,          /* dark colors */
        BLUE,
        GREEN,
        CYAN,
        RED,
        MAGENTA,
        BROWN,
        LIGHTGRAY,
        DARKGRAY,       /* light colors */
        LIGHTBLUE,
        LIGHTGREEN,
        LIGHTCYAN,
        LIGHTRED,
        LIGHTMAGENTA,
        YELLOW,
        WHITE
    };
    #endif

    static int __BACKGROUND = 0;
    static int __FOREGROUND = 7;

    void
    gotoxy(int x, int y)
    {
      COORD c;

      c.X = x - 1;
      c.Y = y - 1;
      SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
    }

    void
    clrscr ()
    {
        DWORD written;

        FillConsoleOutputAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
          __FOREGROUND + (__BACKGROUND << 4), 2000, (COORD) {0, 0},
          &written);
          FillConsoleOutputCharacter (GetStdHandle
          (STD_OUTPUT_HANDLE), ' ',
          2000, (COORD) {0, 0}, &written);
        gotoxy (1, 1);
    }

    #endif

    2. store the file in the include folder
    3. when u want to use it in an app ... just say
    #include <conio.c>

     
    • Curtis Sutter

      Curtis Sutter - 2003-01-19

      I prefer including stdlib.h and using system("CLS");  (My initals  ;-)  ).  Saves having to include conio.h and conio.c

      Curtis

       
    • Dinesh Pillay

      Dinesh Pillay - 2003-01-19

      as i said "possible" solution:) .... man this software is really good .... nice work guys:)

       
    • Dinesh Pillay

      Dinesh Pillay - 2003-01-19

      just wanted to add that system("CLS") or system("PAUSE") ... is a little bit slower to respond than and not as smmoth as clrscr() or getche()

       
    • Anonymous

      Anonymous - 2003-01-19

      .c files should be separately compiled and linked - not included. Only .h files should be included, and these should not contain any data instantiation or function definitions - only (extern) declarations.

      This is more efficient from a compiler point of view, (it only compiles the modules that have changed), and if you have more than one module that includes the same .c files containing function code and/or data instantiation, then linker errors will occur.

      You may be only writing single module apps at present, so do not see the problem - but such bad practices will bite you in the end.

       
    • qWake

      qWake - 2003-01-19

      Question:  What are the Linux/Unix commands equivalent to Windows' CLS and PAUSE commands?  Thanks!

      qWake

       
    • qWake

      qWake - 2003-01-19

      FYI:  I have found CLEAR as the Unix equivalent to Windows' CLS.  But there doesn't seem to be an equivalent to PAUSE as a standard shell command in Unix...

      qWake

       
    • qWake

      qWake - 2003-01-19

      FYI:  I have found CLEAR as the Unix equivalent to Windows' CLS.  But there doesn't seem to be an equivalent to PAUSE as a standard shell command in Unix...

      qWake

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.