clrscr(); and gotoxy(); - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

clrscr(); and gotoxy();

playagainplayagain Posts: 22Member
I use these two functions in animating my words with the help of loops. And it works in Turbo C but when I used it in the dev c/c++ it was all mistake... why? anyone knows?
[code][blue]============================[/blue]
[red]THANK YOU AND GODBLESS !!!
from playagain[/red]
[blue]============================[/blue][/code]
«1

Comments

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : I use these two functions in animating my words with the help of
    : loops. And it works in Turbo C but when I used it in the dev c/c++
    : it was all mistake... why? anyone knows?
    : [code]: [blue]============================[/blue]
    : [red]THANK YOU AND GODBLESS !!!
    : from playagain[/red]
    : [blue]============================[/blue][/code]:

    [blue]
    These functions will only work for Turbo C. In Dev C++ you need to use the Win32 Console API to do these things. Try to compile (in Dev C++) a class I posted on my site:

    http://www.codexxi.com/MyBlocks.html#atConsoleObj

    It mimics the Turbo C style functions in Win32 Console environment.[/blue]
  • playagainplayagain Posts: 22Member

    : [blue]
    : These functions will only work for Turbo C. [color=red][b]In Dev C++ you need to
    : use the Win32 Console API to do these things.[/b][/color] Try to compile (in Dev
    : C++) a class I posted on my site:
    :
    : http://www.codexxi.com/MyBlocks.html#atConsoleObj
    :
    : It mimics the Turbo C style functions in Win32 Console
    : environment.[/blue]

    [color=Purple]I can't understand what you said in red font above.[/color]
    [code][blue]============================[/blue]
    [red]THANK YOU AND GODBLESS !!!
    from playagain[/red]
    [blue]============================[/blue][/code]
  • zibadianzibadian Posts: 6,349Member
    :
    : : [blue]
    : : These functions will only work for Turbo C. [color=red][b]In Dev C++ you need to
    : : use the Win32 Console API to do these things.[/b][/color] Try to compile (in Dev
    : : C++) a class I posted on my site:
    : :
    : : http://www.codexxi.com/MyBlocks.html#atConsoleObj
    : :
    : : It mimics the Turbo C style functions in Win32 Console
    : : environment.[/blue]
    :
    : [color=Purple]I can't understand what you said in red font
    : above.[/color]
    : [code]: [blue]============================[/blue]
    : [red]THANK YOU AND GODBLESS !!!
    : from playagain[/red]
    : [blue]============================[/blue][/code]:

    There's a huge difference between the way DOS and Win32 access the screen and video-cards. In DOS the clrscr could simply place a lot of zeros in a part of the memory, thereby erasing the screen. In Win32 there is no such part in the memory, thus this makes the DOS clrscr useless. To code clrscr in Win32, you need to clear the screenbuffer associated with the console window. Since the OS handles the maintainance of that buffer, you need to tell the OS (i.e. Win32 Console API) to clear the buffer.
  • playagainplayagain Posts: 22Member
    I still can't get it ???
    Here is my code:

    [code]
    #include

    main()
    {

    int a;

    clrscr();

    for(a=1;a<=77;a++)
    {
    clrscr();
    gotoxy(a,12);
    printf("CUTE");
    delay(3000);
    }

    getche();

    }
    [/code]


    My code worked in Turbo C but in some compiler it does'nt work... What could shall I put to show same output.???
    [code][blue]============================[/blue]
    [red]THANK YOU AND GODBLESS !!!
    from playagain[/red]
    [blue]============================[/blue][/code]
  • zibadianzibadian Posts: 6,349Member
    : I still can't get it ???
    : Here is my code:
    :
    : [code]:
    : #include
    :
    : main()
    : {
    :
    : int a;
    :
    : clrscr();
    :
    : for(a=1;a<=77;a++)
    : {
    : clrscr();
    : gotoxy(a,12);
    : printf("CUTE");
    : delay(3000);
    : }
    :
    : getche();
    :
    : }
    : [/code]:
    :
    :
    : My code worked in Turbo C but in some compiler it does'nt work...
    : What could shall I put to show same output.???
    : [code]: [blue]============================[/blue]
    : [red]THANK YOU AND GODBLESS !!!
    : from playagain[/red]
    : [blue]============================[/blue][/code]:

    Download the code AsmGuru62 gave you. In there is a gotoxy() procedure and a clrscr() procedure. Change your code to use those instead.
  • playagainplayagain Posts: 22Member
    I downloaded the code of asmguru but when I opened it, I was surprised because I can't understand the code... Kindly give me a revised code of my code that works in dev c/c++ or at other compilers rather than turbo c ???

    Please Please Please :) :) :)
    [code][blue]============================[/blue]
    [red]THANK YOU AND GODBLESS !!!
    from playagain[/red]
    [blue]============================[/blue][/code]
  • MT2002MT2002 Posts: 1,444Member
    : I downloaded the code of asmguru but when I opened it, I was
    : surprised because I can't understand the code... Kindly give me a
    : revised code of my code that works in dev c/c++ or at other
    : compilers rather than turbo c ???
    :
    : Please Please Please :) :) :)
    : [code]: [blue]============================[/blue]
    : [red]THANK YOU AND GODBLESS !!!
    : from playagain[/red]
    : [blue]============================[/blue][/code]:
    [color=Blue]clrscr() and gotoxy() are [b]borland[/b] specific.
    For refrence, [b]graphics.h[/b] is borland specific as well, so
    it wont work either.

    Windows does not allow 32bit programs direct access to memory.
    This is to protect other programs and data to be overwritten.

    Under DOS, text mode memory is useually b800h:0, which can be
    accessed through a pointer, so it is easy to create clrscr()
    and gotoxy(). However, DevC++ compilies 32bit programs, so
    Windows will not allow this.

    In order to access system resources (such as text mode memory),
    you have to go through Windows. To do this, you need to use the
    Win32 PSDK (Platform Software Development Kit) ak, the Win32 API.

    [link=http://msdn2.microsoft.com/en-us/default.aspx]MSDN can be a great refrence[/link]

    [link=http://www.winprog.org/tutorial/]Forgers Win32 API tutorial[/link]

    Hope this helps!

    @PH Staff: Thanks alot for adding the link tag!:-)[/color]
  • LundinLundin Posts: 3,711Member
    [color=Blue]Posted this before...:[/color]


    [code]/* ConsoleFunctions.h */

    #ifndef __WINAPI_CONSOLE_WRAPPER_H
    #define __WINAPI_CONSOLE_WRAPPER_H

    void gotoxy (int x, int y);
    void clrscr (void);

    #endif /* __WINAPI_CONSOLE_WRAPPER_H */



    [/code]


    [code] /* ConsoleFunctions.c */
    #include "ConsoleFunctions.h"
    #include

    void gotoxy(int x, int y)
    {
    static HANDLE hStdout = NULL;
    COORD coord;

    coord.X = x;
    coord.Y = y;

    if(!hStdout)
    {
    hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
    }

    SetConsoleCursorPosition(hStdout,coord);
    }

    void clrscr(void)
    {
    static HANDLE hStdout = NULL;
    static CONSOLE_SCREEN_BUFFER_INFO csbi;
    const COORD startCoords = {0,0};
    DWORD dummy;

    if(!hStdout)
    {
    hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleScreenBufferInfo(hStdout,&csbi);
    }

    FillConsoleOutputCharacter(hStdout,
    ' ',
    csbi.dwSize.X * csbi.dwSize.Y,
    startCoords,
    &dummy);
    gotoxy(0,0);
    }

    [/code]
  • playagainplayagain Posts: 22Member
    I really appreciate your efforts but I'm a beginner in C so I still can't understand what are the essence of your codes in my problems. Can someone with kindhearted help me to understand those codes and where to put them?
    [code][blue]============================[/blue]
    [red]THANK YOU AND GODBLESS !!!
    from playagain[/red]
    [blue]============================[/blue][/code]
  • LundinLundin Posts: 3,711Member
    Take what I posted and make a .h file and a .c file of it. Then include the .h file from your program and add the .c to the project, compile link & run.

    [code]#include "ConsoleFunctions.h"
    #include
    #include

    int main(void)
    {
    printf("Printing something
    ");
    system("pause");
    clrscr();
    printf("Screen is cleared
    ");

    return 0;
    }[/code]
«1
Sign In or Register to comment.