how to use clrscr and gotoxy function in Devc++ complier

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tirupathi Rao
    New Member
    • Apr 2013
    • 1

    how to use clrscr and gotoxy function in Devc++ complier

    how to use clrscr and gotoxy function in Devc++ complier//
    even though i included header file of clrscr and gotoxy
    Devc++ compiler giving an error .can i know how to use them.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Maybe you could post the errors you are getting?

    Comment

    • lego13
      New Member
      • May 2013
      • 3

      #3
      gotoxy only works on systems that are compatible with IBM PC. A similar feature is in Turbo Pascal. The function is not compatible with Windows.

      clrscr() can be used only in Borland C compiler. You may use system("cls");

      Comment

      • Yahia1111
        New Member
        • May 2013
        • 1

        #4
        Clear screen "clrscr() is not a standard function, niether in C or C++. So, using clrscr() is not always give you an answer, and it depends upon the compiler you installed and what library is available too. Some says: include library as: #include <conio.h> , this is also does not help much, and most of the times, it does not work because this library : <conio.h> is not standard library too.
        So, to use clear screen, you have to use :
        Code:
        #include <iostream> WHICH IS KNOWN IN C++ and  system("cls"); as in the following example:
        #include <stdio.h>  
                   // #include <conio.h> some compilers      
                   //ask for this library, but in our case, no need.
        #include <iostream> // available in C++ standard Library 
        int main()
        {
            char x;
            
            
         for(int j=0; j<=10;j++)
         {
                 
            printf("Press any key to clear the screen.\n");
            scanf("%c",&x);
            // >>>>>>>>>>>>>>>>>  clrscr();  you can not use it in
            // some compilers.......>>>>>>>>>><<<<<<
            //   instead  use this one:   system("cls"); 
           system("cls");     
        //clearscrean then leave 3 linsbefore writing vnew things
           for(int k=0;k<=3;k++)
           printf("\n");
           for(int i=0; i<=3;i++)
           {                  // repeat each of the following
                              // line  4 times
                   for(int m=65;m<=80 ;m++)  
         //m=65 is equivalant to character 'A' and so  on.....  
                   printf("%c",m); // print  m  as characters  and
                                   // not as decimal
          printf("----Look at value of j after each  clearscreen YAHIA111%d",j);  
                   printf("\n");
           }
           
           scanf("%c",&x);
        }
           return 0;
        }
        Last edited by Rabbit; May 8 '13, 04:35 PM. Reason: Please use code tags when posting code.

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          Avoid using the system() function.

          Firstly, the argument must be a valid command which can vary by operating system so your code may not be portable.

          Secondly, you have no idea how many other calls will be made in order to execute your argument. You may find that two users of the same OS will may succeed or fail based on what installed utilities are on the respective machines.

          Thirdly, you may have security issues since you can't tell what credentials are required to run your command. Maybe it works for you running as administrator but fails for your user who is not.

          Instead try to not write a windowed program using the console. The console was written to emulate a teletype that has a roll of paper that feeds through it. Put your displays on the bottom line and let the display scroll.

          Comment

          Working...