Menu

C++ in DOS "shutdown key"

2002-12-15
2012-09-26
  • Nobody/Anonymous

    Is there a way so that when a key is pressed it will automaticlly shut down the program? Or do you always have to press enter? My program displays a line of flashing text, but I can not figure out a way to shut down the program by hitting one key and then hitting "enter".

     
    • Nobody/Anonymous

      it posted twice don't know why but it did, sorry about that.

       
    • Nobody/Anonymous

      Console programs are shut down with ctrl-c and other with alt-f4, but you have to make sure to free allocated memory etc.

      tkorrovi

       
    • Anonymous

      Anonymous - 2002-12-15

      try this code...

      Zero Valintine

      #include <iostream>
      #include <cstdlib>
      #include <conio.h>

      int main(){
      getche();
      return(0);}

       
    • j@ck_

      j@ck_ - 2002-12-15

      Here is a small program to show one way to do that:

      #include <iostream>
      #include <cstring>                             
      using namespace std;

      void doneover();

      int main()
      {
        char s[80];
        char *p1;

        do {
       
         doneover();
       
          p1 = s;                                    
          cout << "To Exit: Enter  done ";
          gets(p1);                            
        } while(strcmp(s, "done"));
      }

      void doneover()
      {
        cout <<" here is your program\n" ;
         }

       
    • Nobody/Anonymous

      Look for tutorials on signal handling. =)

      Kip

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.