Thread: system pause

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

    system pause

    i need a way to simulate using the code system(pause); but without it saying "press any ket to continue . . ." how can i do this?
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    10
    There are several ways to do it. You could use a for loop, but it would be processor dependant. You could also write your own time function for your pause. It would then pause for however many seconds you wanted on any system. Include the time.h & clock( ) & you'll need to do something like( example only for understanding )...
    Code:
    void timeout( int seconds )
    {
    clock_t endtime = clock( ) + seconds * CLOCKS_PER_SEC;
    while( clock( ) < endtime );
    }
    -fox

  3. #3
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    i have no clue wut that meant. im sorta a newb
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  4. #4
    Registered User
    Join Date
    Jul 2002
    Posts
    10
    How long do you want your pause to be? Post a little code so we can see what you're trying to do & we'll help you. It will most likely not be me though as I need to run for now.

    -fox

  5. #5
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    untill the user presses enter
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  6. #6
    Registered User
    Join Date
    May 2002
    Posts
    317
    Here you go, this code snippet will wait until the user presses 'ENTER' (char 32) to continue:

    Code:
    #include<iostream>
    #include <conio.h>
    
    using namespace std;
    
    
    int main(void){
    	char keycode;
              int keypress = 1;
    
    	while(keypress){
    		if(kbhit()){
    			keycode = getch();
    			if ((keycode = (char)13))
    				keypress = 0;
    		}
    	}
    	return(0);
    }
    Last edited by Traveller; 07-17-2002 at 04:00 AM.

  7. #7
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    does main have to be void?
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  8. #8
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    > does main have to be void?

    int main (void) or int main(int argc, char *argv[] is what you want...

  9. #9
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    adn do i put the code after the snipet u gave me not including the header and stuff. or like INSIDE it if oy know what i mean
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  10. #10
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    meaning
    Code:
    // some previous program here
    	char keycode;
              int keypress = 1;
    
    	while(keypress){
    		if(kbhit()){
    			keycode = getch();
    			if ((keycode = (char)13))
    				keypress = 0;
    		}
    	}
    //rest of the program here
    like that\?
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  11. #11
    Unregistered
    Guest
    Code:
    //Traveller's code
    while(keypress){
    		if(kbhit()){
    			keycode = getch();
    			if ((keycode = (char)13))
    				keypress = 0;
    		}
    	}
    Just think things through. You use this where you want your pause. The code that Traveller gave you will wait for the "Enter keypress". So in your program you are doing, think about where you want the program to wait for "Enter keypress" and use this part of Traveller's code and it will work fine there.

    -fox

  12. #12
    Registered User
    Join Date
    Jul 2002
    Posts
    10
    oops, I did not log in my last post.

    -fox

  13. #13
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    it syas kbhit cannot be used as a function
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  14. #14
    Registered User
    Join Date
    May 2002
    Posts
    317
    kbhit() is a function. What compiler and what include files do you have?

  15. #15
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    look in my signiture, have u noticed everyone puts their compiler in their sig! as for the header file0s..

    #include <iostream>
    #include <string>
    #include <stdlib.h>
    #include <windows.h>
    #include <conio.h>
    #include <fstream>
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 05:35 PM
  2. Press a key
    By siavoshkc in forum C++ Programming
    Replies: 30
    Last Post: 01-21-2006, 10:15 AM
  3. New system build wont boot
    By lightatdawn in forum Tech Board
    Replies: 7
    Last Post: 12-02-2005, 06:58 AM
  4. BIOS system and memory allocation problem
    By beely in forum Tech Board
    Replies: 9
    Last Post: 11-25-2003, 07:12 AM
  5. Problem Reporting System. Need Advide!
    By brunomiranda in forum Tech Board
    Replies: 9
    Last Post: 09-25-2003, 09:21 PM