Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

the sleep(10) function is not working i have mac plz help

+6 votes
asked Mar 23 by Black Chicken (180 points)

2 Answers

0 votes
answered Mar 25 by Peter Minarik (54,560 points)

Please, be specific about your question

What language are we talking about (C I'd assume from your tag)?

Is there any error message or warning?

Are you running it on OnlineGDB or on your own (Mac) computer? (If on online GDB, it is rather irrelevant that you have a Mac.)

The best course of action would be to share your code that does not work. You can link your entire project via the SHARE button (3 to the right from the RUN button).

C language specific

If you're talking about the sleep() in C, then the C standard does not have a sleep() function. Individual distributions have their own implementation. Check this out.

Probably all you're missing is the following include:

#include <unistd.h>
+1 vote
answered May 12 by Samarth Matam (160 points)
The sleep function is not defined in the standard library of c that is, "stdio.h". It is defined the the unistd header file which when included in some compilers, an error is thrown saying the unistd library cannot be found. There are 3 ways to combat this:
1. If you have a compiler that accepts the unistd header file, then include it and use the sleep function.

2. If you do not have a compiler that accepts the unistd header file, then don't worry there is an alternative for the sleep function defined in the windows.h header file. This function is known as Sleep() with a capital 'S'. It takes its argument/parameter in milliseconds so if you want it to sleep for 1 second you will have to pass argument as Sleep(1000) as 1 second = 1000 milliseconds.

3. Now something weird about onlinegdb compiler is that even though you do not include the unistd header file, you can still use the sleep() function by including conio.h and stdlib.h

Hope this helped you!
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...