Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Quiting a program, C.

  • 01-11-2006 12:23am
    #1
    Registered Users, Registered Users 2 Posts: 9,844 ✭✭✭


    Hiya,

    Is there a piece of code in C that makes the program quit out of Dos completely.

    For example, if the user types a specific key the entire program closes rather than reverting back to C:\ or whatever.

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 9,844 ✭✭✭py2006


    ooooooooooo K!!!

    Well I know you can use the break; command to quite the program!

    But is there a command that actually exits out of DOS altogether?


  • Registered Users, Registered Users 2 Posts: 2,082 ✭✭✭Tobias Greeshman


    What are you trying to do, quit your application on some input or quit the application and the dos window that ran the application?

    And also why?


  • Registered Users, Registered Users 2 Posts: 9,844 ✭✭✭py2006


    silas wrote:
    What are you trying to do, quit your application on some input or quit the application and the dos window that ran the application?

    And also why?

    Well, I am working on a program that has 10 options for the user. Each option doing a seperate thing.

    If they select 10 the progam should not only quit out of dos altogether.


  • Registered Users, Registered Users 2 Posts: 2,082 ✭✭✭Tobias Greeshman


    For option 10 the application just simply ends, to actually quit the dos box, would require an windows api call, which i think is a little bit too advanced for this application.

    To quit the application you can use return, exit or abort calls. However the best approach is to have a loop after input is taken in that loops until option 10 is selected, so control bypasses the loop and the program just naturally terminates by hitting the "return 0" line or the end of main().


  • Closed Accounts Posts: 583 ✭✭✭monkey tennis


    Why don't you just... not run it in DOS in the first place? Give them an icon to double-click on. This will run the application in a console, then close the window when the program exits.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 885 ✭✭✭clearz


    As monkey tennis said already if the user just clicks on the exe then the program will exit automatically once finished but I took the time to show you how its done anyway. The following will close the dos window. Just integrate it into your code as needed.
    #define _WIN32_WINNT 0x0500 // Needed for GetConsoleWindow.
    #include <windows.h>
    
    int main(int argc, char* argv[])
    {
        HWND hWnd = GetConsoleWindow(); // Get a pointer to the console window
        SendMessage(hWnd, WM_CLOSE, NULL, NULL); // Send a close message to the window
        return 0;
    }
    
    


Advertisement