command to shutdown exe

This is a discussion on command to shutdown exe within the C Programming forums, part of the General Programming Boards category; Hello. I want to shutdown a code if some condition is met. Code: if(condition is true){ some command to end ...

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    11

    command to shutdown exe

    Hello.
    I want to shutdown a code if some condition is met.
    Code:
    if(condition is true){
      some command to end the exe
    }
    for example,
    Code:
    #include <stdio.h>
    #include <math.h>
    int main()
    int a;
    scanf("%d",&a);
    if(a==5){
    (command to shutdown application)
    }
    else{
    ...
    }
    system("PAUSE");
    }
    Thanks.
    D.

  2. #2
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by Jalo View Post
    Hello.
    I want to shutdown a code if some condition is met.
    Use exit from stdlib.h .
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    Or just
    Code:
    return 0;
    if you are in main().

    The returned integer is a primitive way of telling the OS whether the program execution is successful. 0 means success. Anything other than 0 means failure.

  4. #4
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by cyberfish View Post
    The returned integer is a primitive way of telling the OS whether the program execution is successful.
    What is the 'modern' way ?
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    There is no 'modern' way.

    To do anything more sophisticated there will need to be some way to classify failures, and an OS is too general purpose to do that.

  6. #6
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    383
    It doesn't really matter anyway, since the OS doesn't care if the program was "successful" or not. The status code from a program is generally used by other programs and scripts to decide what to do on success or failure. A small integer is enough to indicate this.

    This applies to systems like Windows and *nix, at least. Systems like VMS have a more sophisticated concept of return codes, but even on those systems you return 0 or EXIT_SUCCESS from C to indicate success and EXIT_FAILURE for failure.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Shutdown
    By Queatrix in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 04-01-2007, 03:15 PM
  2. shutdown by c....
    By ruku in forum C Programming
    Replies: 3
    Last Post: 07-24-2006, 12:14 PM
  3. shutdown()
    By Hunter2 in forum Networking/Device Communication
    Replies: 6
    Last Post: 03-18-2004, 06:43 PM
  4. closesocket and shutdown
    By Hunter2 in forum Networking/Device Communication
    Replies: 2
    Last Post: 08-03-2003, 12:53 PM
  5. Shutdown (again)
    By ihsir in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 05-05-2002, 11:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21