help with code

This is a discussion on help with code within the C++ Programming forums, part of the General Programming Boards category; i need hepkl wiht two thigns i searhced hte board for and everything. 1. how do i have it so ...

  1. #1
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608

    help with code

    i need hepkl wiht two thigns i searhced hte board for and everything. 1. how do i have it so when the user presses the escape key the program automaticly shiuts itslef down during anytime of the program, and isnt the sleep code sleep (1000);
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    please, PLEASE:
    1)look before you type each letter
    2)if you're starting a numbered list, remember to include the number that comes after one

    to answer your question:
    exit(0);
    and yes, sleep(1000); should work.

  3. #3
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    for the exit(0); i need it so as soon as you press esc the program shuts off

    and when i used the slep command i get this eerror

    implicit declaration of function `int sleep(...)'

    i used this code on the line of the error

    sleep (1000);
    Last edited by Klinerr1; 07-16-2002 at 12:34 AM.
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  4. #4
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    for the exit(0); i need it so as soon as you press esc the program shuts off
    you might need to rewrite your program to do that. essentially, you need to check the keyboard buffer many times a second for the esc key, and use exit(0) when that happens
    and when i used the slep command i get this eerror

    implicit declaration of function `int sleep(...)'
    you probably forgot to include a header file. my suggestion is to look it up online, or you can do trial and error with most common header files.[/QUOTE]

  5. #5
    Registered User
    Join Date
    Jun 2002
    Posts
    6
    Sleep() is a function in windows.h (make sure to include windows.h and also make sure that you are case sensative in calling the function). getch() is the function you are going to want to use for getting pressed keys. EXAMPLE:

    Code:
    #include <iostream.h>
    #include <conio.h>
    
    #define ESC 27
    
    int main()
    {
    	char chartron;
    	while(true)
    	{
    		if(kbhit())
    			chartron=getch();
    		if(chartron==ESC)
    			return 0;
    	}
    	return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 09:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 08:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM

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