Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5428
Number of posts: 16949

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
clrscr(); and gotoxy(); Posted by playagain on 29 Apr 2007 at 8:59 AM
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?
============================
THANK YOU AND GODBLESS !!!
from playagain
============================
Report
Re: clrscr(); and gotoxy(); Posted by AsmGuru62 on 30 Apr 2007 at 3:39 AM
: 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?
:
: ============================
: THANK YOU AND GODBLESS !!!
: from playagain
: ============================
:


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.
Report
Re: clrscr(); and gotoxy(); Posted by playagain on 30 Apr 2007 at 8:49 PM

:
: 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.


I can't understand what you said in red font above.
============================
THANK YOU AND GODBLESS !!!
from playagain
============================
Report
Re: clrscr(); and gotoxy(); Posted by zibadian on 30 Apr 2007 at 9:39 PM
:
: :
: : 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.

:
: I can't understand what you said in red font
: above.

:
: ============================
: THANK YOU AND GODBLESS !!!
: from playagain
: ============================
:

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.
Report
Re: clrscr(); and gotoxy(); Posted by playagain on 30 Apr 2007 at 9:48 PM
I still can't get it ???
Here is my code:

#include <stdio.h>

main()
{

int a;

clrscr();

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

getche();

}



My code worked in Turbo C but in some compiler it does'nt work... What could shall I put to show same output.???
============================
THANK YOU AND GODBLESS !!!
from playagain
============================
Report
Re: clrscr(); and gotoxy(); Posted by zibadian on 30 Apr 2007 at 10:49 PM
: I still can't get it ???
: Here is my code:
:
:
: 
: #include <stdio.h>
: 
: main()
: {
: 
: int a;
: 
: clrscr();
: 
: for(a=1;a<=77;a++)
: {
:       clrscr();
:       gotoxy(a,12);
:       printf("CUTE");
:       delay(3000);
: }
: 
: getche();
: 
: }
: 
:
:
:
: My code worked in Turbo C but in some compiler it does'nt work...
: What could shall I put to show same output.???
:
: ============================
: THANK YOU AND GODBLESS !!!
: from playagain
: ============================
:

Download the code AsmGuru62 gave you. In there is a gotoxy() procedure and a clrscr() procedure. Change your code to use those instead.
Report
Re: clrscr(); and gotoxy(); Posted by playagain on 1 May 2007 at 6:46 AM
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 :) :) :)
============================
THANK YOU AND GODBLESS !!!
from playagain
============================
Report
Re: clrscr(); and gotoxy(); Posted by MT2002 on 1 May 2007 at 4:48 PM
: 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 :) :) :)
:
: ============================
: THANK YOU AND GODBLESS !!!
: from playagain
: ============================
:
clrscr() and gotoxy() are borland specific.
For refrence, graphics.h 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.

MSDN can be a great refrence

Forgers Win32 API tutorial

Hope this helps!

@PH Staff: Thanks alot for adding the link tag!
Report
Re: clrscr(); and gotoxy(); Posted by Lundin on 3 May 2007 at 11:59 PM
Posted this before...:


/* 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 */






 /* ConsoleFunctions.c */
#include "ConsoleFunctions.h"                      
#include <windows.h>
   
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);
}

Report
Re: clrscr(); and gotoxy(); Posted by playagain on 4 May 2007 at 1:16 AM
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?
============================
THANK YOU AND GODBLESS !!!
from playagain
============================
Report
Re: clrscr(); and gotoxy(); Posted by Lundin on 4 May 2007 at 1:56 AM
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.

#include "ConsoleFunctions.h"
#include <stdio.h>
#include <stdlib.h>
  
int main(void)
{     
  printf("Printing something\r\n");
  system("pause"); 
  clrscr();
  printf("Screen is cleared\r\n");
  
  return 0;  
}
Report
Re: clrscr(); and gotoxy(); Posted by Moradi on 2 Feb 2012 at 4:12 AM
It's so easy just try
system("cls")
instead of clrscr() I think it will work.
B)



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.