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?
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?
perhaps this?
Code:#include <ctime>
Double Helix STL
Code:void wait ( int seconds ) { clock_t endwait; endwait = clock () + seconds * CLK_TCK ; while (clock() < endwait) {} }
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
You're right, Sleep(); is better. That's in milliseconds, right? So, Sleep(1000);
Yes, it's in milliseconds. Sleep(1000); is about 1 second. Make sure to:However, it's platform dependent!Code:#include <windows.h>
Videogame Memories!
A site dedicated to keeping videogame memories alive!
http://www.videogamememories.com/
Share your experiences with us now!
"We will game forever!"
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
Double Helix STL
You're kidding, right?
C and C++ don't have sleep() as part of the standard.
I believe its Sleep() - the WinAPI, and sleep() - the windows.h function.
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.
Sleep() - win32
sleep() - *nix
Or did our friend want this wait()...Code:void wait(size_t ms) { #ifdef WIN32 #include <windows.h> Sleep(ms); #else #include <unistd.h> usleep(ms); #endif }
Last edited by jafet; 01-19-2007 at 11: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;}
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 07: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
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler