Why not just use the standard sleep() function if your compiler has it. It would do the same thing.
Why not just use the standard sleep() function if your compiler has it. It would do the same thing.
could you please explain, relating it to my code, how i can use a sleep function. i don't know if this is correct, but if i do:
Code:void AI(void){ unsigned int sleep = 1000; if (yR2 > yBall) { if (yR2 > RACKET ) { sleep(1000); yR2--; } }that still gives me the exact same error.Code:
as far as errors to this code,Code:#include <unistd.h> int main(int argc, const char **argv) { if ( argc < 2) { printf("no input\n" "Input a number to se if odd or even\n"); return -1; } sleep(10); printf("I just slept for 10 seconds\n"); return 0; }
me as well as others are going to need to see more then just that to see what errors you're talking about.Code:void AI(void){ unsigned int delay = 1000; if (yR2 > yBall) { if (yR2 > RACKET ) { delay(1000); yR2--; } }
-- besides this. what function is called delay, and why you making a variable called delay then using a function called delay then putting in the same amount of your variable called delay into that function by the same name?
Last edited by userxbw; 12-10-2017 at 03:09 PM.
#include <unistd.h> did you put that in your code?
Post your entire program, anyone can post a function and ask why is this not working when the function has vars or struct and stuff in the function that are not explained for someone else to know what they are.
I think someone already asked if they , your variables are global or not.
Code:void AI(void){ unsigned int delay = 1000; if (yR2 > yBall) { if (yR2 > RACKET ) { delay(1000); yR2--; }
Last edited by userxbw; 12-10-2017 at 03:17 PM.
the code i provided is for a pong game, its just delaying the racket movement
secret code, I get it. Ok. do you know what the difference between global and local and protected when it comes to data types and their access to them?
because if your, yR2, yBall, yR2, RACKET are not global then how will that function see them to determine what they are, and I nor others do not really even know what errors your compiler/program is throwing even. I have not seen that information. if they are not global then you're going to need to pass them into your function.
they're all global variables, that isn't the problem
Providing you add the following at the top of your .c file or in a header file called by your .c file, it should work. Please read the man page for sleep(). The argument to sleep() is the number of seconds, so 1000 is over 16 minutes! ;^)
Code:#include <unistd.h>
that you have a function that does not have it's header included into that file you are using the function in so it has no idea what to do with it. you're missing the header file that has the proto type for the function to it can link it to the object file of the same.
google says
so that tells me it is a DOS (really old media) function, dos.h is where the delay function is located.Here unsigned int is the number of milliseconds (remember 1 second = 1000 milliseconds). To use delay function in your program you should include the "dos.h" header file which is not a part of standard C library.
Like others have been showing you, I'd change my implementation to that loop if you cannot get sleep to work. Just expenment to see how long that loop last depending on what number you put into it to get you're 1000 seconds.
or x * 60 to get minutes. ie 1 * 60 = 1 minute. etc...
that is using sleep.
Last edited by userxbw; 12-10-2017 at 03:55 PM.
i'm so confused, i've never used dos.h before. i thought creating a delay was an easy little thing.
in my code the way it, can you explain how i can create a simple delay without using delay or sleep, what is it i have to do