Thread: clear screen function

  1. #1
    Registered User mrprogrmr's Avatar
    Join Date
    Dec 2004
    Posts
    9

    clear screen function

    Hi Frendz,
    A meal fr u.......
    Can u bring out atleast 10 errors out of it....
    Itz gonna clear the screen



    Code:
    
    void cls()
    {
    
    POINT pt;
    HDC hdc;
    MoveToEx(hdc,0,0,&pt);
    HANDLE  hConsoleOut; 
    DWORD    dummy;
    COORD    Home = { 0, 0 };
    hConsoleOut = GetStdHandle( STD_OUTPUT_HANDLE );
    FillConsoleOutputCharacter(hConsoleOut, ' ', pt.x * pt.y, Home, &dummy );
    pt.x=0;
    pt.y =0;
    MoveToEx(hdc,pt.x,pt.y ,&pt);
    }
    

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Hey I know what I'll do! I'll post a snippet of code, which calls functions that aren't any kind of standard function, with typedefs that aren't anything anyone knows what they are, and then I'll tell everyone to find the errors in it! GOOD IDEA!

    Go read the FAQ entry. While you're at it, learn how to type. No one wants to read that.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    20
    Can u bring out atleast 10 errors out of it....
    You wrote this and expect so many errors? Or is this an assignment that you have to do?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by [Ren]
    You wrote this and expect so many errors? Or is this an assignment that you have to do?
    Either that or it is giving them errors, and they're too stupid to post them here. But I suspect you're right. Although it does lean towards the "too stupid" side of things also...

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Since you are using windows, I suggest you read the following article on how to correctly clear the screen.
    http://support.microsoft.com/kb/q99261/

  6. #6
    Registered User mrprogrmr's Avatar
    Join Date
    Dec 2004
    Posts
    9
    hey.. so silly of me .. i thought people are aware of some header files known as "Windows.h"
    functions that aren't any kind of standard function
    . Besides they keep MSDN as the holy "BIBLE".
    typedefs that aren't anything anyone knows what they are
    This was indeed a utility i wud have other wise used in my application.

    And I dare not to underestimate the brilliance of big guns.. yeh i admit i m new..groomin

  7. #7
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    hey.. so silly of me .. i thought people are aware of some header files known as "Windows.h"
    Yeah, well...I do 100% of my coding in linux. And MFC is anything but standard C.
    If you understand what you're doing, you're not learning anything.

  8. #8
    Quote Originally Posted by mrprogrmr
    i thought people are aware of some header files known as "Windows.h"
    You know, man, I'm programming for embedded systems... I haven't a clue what "windows.h"' is... (well, sort of...)
    Emmanuel Delahaye

    "C is a sharp tool"

  9. #9
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Your code actually produces about 3 times that many errors. Why? Because you're not showing us all your code. How are we supposed to know you included windows.h? What else did you include?

    In futute, post all of the relevant code. Ask an actual question, instead of simply expecting us to do your debugging for you, and TYPE PROPERLY!

  10. #10
    Registered User mrprogrmr's Avatar
    Join Date
    Dec 2004
    Posts
    9
    so sorry, i feel, for not giving the entire source code.
    this was not that i had wished.
    Here is the complete one..


    Code:
    
    #include <stdio.h>
    #include <conio.h>
    #include <Windows.h>
    void cls();
    int main()
    {
    	
    printf("I wish to clear the screen but prior to this i would type some nuisance to it"
    "\n so that i find the screen cleared as before. So i have written the utility\n"
    " Yes, I cud have used \" system (cls) \" function but i wanted my own utility.\n"
     "\n I also wanted it to be fail proof. I have been using this utility for about"
     "\n 2 months. It suffers some limitations ,i know ,but i still want others to "
     " \n do me favors making it good.\n");
    	
    printf("\n\t\tPress any key clear the  screen\n");
    	
    	int p=getch();
    	cls();
       printf("\n Hope now u get what I meant.\n");
    
       printf("\n\t\t Press any key clear the  screen\n");
       p=getch();
    	cls();
    	
    	int k=getch();
    	return 0;
    }
    
    void cls()
    {
    	
         POINT pt;
         HDC hdc;
         MoveToEx(hdc,0,0,&pt);
         HANDLE  hConsoleOut; 
         DWORD    dummy;
         COORD    Home = { 0, 0 };
         hConsoleOut = GetStdHandle( STD_OUTPUT_HANDLE );
         FillConsoleOutputCharacter( 
                     hConsoleOut, ' ', pt.x * pt.y,   Home,  &dummy );
         pt.x=0;
         pt.y =0;
         MoveToEx(hdc,pt.x,pt.y ,&pt);
    
    }
    


    I infact want it to be free of errors and better .. Any suggestion to make it better would be a highness.

  11. #11
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    Is this a joke ?
    If so let me tell you straight away : it sucks.
    If not get of your high horse.

  12. #12
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    And to top it off, you use C99 which isnt supported by a great deal of compilers. (still with errors though).
    Last edited by Shakti; 12-28-2004 at 03:23 AM.

  13. #13
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Hmm.... if you read this you'll see how to clear the screen. Now as for your 'great' programming knowledge please refer to the windowsconsole option at the bottom.

    Wait you know what I'll put that option on here for you to see:

    Code:
    #include <windows.h> 
    
    void clrscr(void)
    {
        COORD                       coordScreen = { 0, 0 };
        DWORD                       cCharsWritten;
        CONSOLE_SCREEN_BUFFER_INFO  csbi;
        DWORD                       dwConSize;
        HANDLE                      hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        GetConsoleScreenBufferInfo(hConsole, &csbi);
        dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
        FillConsoleOutputCharacter(hConsole, TEXT(' '), 
                                   dwConSize, coordScreen, &cCharsWritten);
        GetConsoleScreenBufferInfo(hConsole, &csbi);
        FillConsoleOutputAttribute(hConsole, csbi.wAttributes, 
                                   dwConSize, coordScreen, &cCharsWritten);
        SetConsoleCursorPosition(hConsole, coordScreen);
    }
    It looks real similar to your code . . . . . . hmmm.

    Maybe because they both came from MSDN????
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  14. #14
    Registered User
    Join Date
    Dec 2004
    Location
    Oklahoma City
    Posts
    55
    When it comes to

    Code:
    system("cls");
    Can that be placed anywhere within your code? I'm doing an exercise that says to "Clear the screen using the system command "cls" or "clear" before the program executes".

    Running the program for this exercise without the system command starts with a cleared screen anyhow, so, what good would it be in this situation? With or without the command I get the same results.

  15. #15
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Your program has quite a few problems as the others have charmingly pointed out.

    I think you would be better posting questions like this, which are Windows specific, on the Windows specific board. This board is strictly for C issues.

    You are mixing Windows GUI routines, MoveToEx() for example, (which wouldn't work anyway as you do not initialise hdc), with Windows Console calls, GetStandardHandle() etc.

    I have a 6 part Console programming tutorial on my site starting here. Clearing the screen, moving the cursor and a whole load of other stuff is covered in there.

    Loosing the "funky, cool" typing style may help reduce peoples hostility, it really does annoy.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Clear Screen Function?
    By Punkture in forum C Programming
    Replies: 3
    Last Post: 05-05-2003, 09:25 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM