'wait' undeclared?

This is a discussion on 'wait' undeclared? within the C++ Programming forums, part of the General Programming Boards category; OK I feel really stupid for this, but I can't get it to work. I thought you just needed #include<time.h> ...

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    10

    Question 'wait' undeclared?

    OK I feel really stupid for this, but I can't get it to work. I thought you just needed #include<time.h> at the top to use it, but obviously not, so can anyone tell me what it should be instead of time.h please?

  2. #2
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    perhaps this?

    Code:
    #include <ctime>
    I'm just trying to be a better person - My Name Is Earl

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Code:
    void wait ( int seconds )
    {
      clock_t endwait;
      endwait = clock () + seconds * CLK_TCK ;
      while (clock() < endwait) {}
    }

  4. #4
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    That is a very bad wait function consider what it is doing... you are putting it into an loop where it will be sucking up the processor hardcore. A better solution is Sleep/sleep, search it on the board to find a nice function that is crossplatform

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    You're right, Sleep(); is better. That's in milliseconds, right? So, Sleep(1000);

  6. #6
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Yes, it's in milliseconds. Sleep(1000); is about 1 second. Make sure to:
    Code:
    #include <windows.h>
    However, it's platform dependent!
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  7. #7
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    Oh and remember the uppercase issue with sleep().

    In C it is:

    sleep(1000);

    In C++ it is:

    Sleep(1000);

    Very easy mistake to make
    I'm just trying to be a better person - My Name Is Earl

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    You're kidding, right?

  9. #9
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,458
    C and C++ don't have sleep() as part of the standard.

    I believe its Sleep() - the WinAPI, and sleep() - the windows.h function.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  10. #10
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Sleep() - win32

    sleep() - *nix

  11. #11
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Code:
    void wait(size_t ms)
    {
        #ifdef WIN32
            #include <windows.h>
            Sleep(ms);
        #else
            #include <unistd.h>
            usleep(ms);
        #endif
    }
    Or did our friend want this wait()...
    Last edited by jafet; 01-19-2007 at 10:55 PM.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  12. #12
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    I ... don't think it's a very good idea to include headers within functions.

    Oh no, I really don't.

    What happened to the xp_sleep functions I posted a few weeks back? The board can't find them, and neither can the other board at which I post regularly.
    Last edited by CornedBee; 01-20-2007 at 06:56 AM.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  13. #13
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  3. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM

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