+ 1

TIMER

Is there a way to take “time” in the C languages like wait(5) second before execute my program

28th May 2024, 7:55 PM
CLASSICBOI
CLASSICBOI - avatar
3 Answers
+ 3
threads are related to OS and putting them for sleep is a process of OS, not of the programming language. Starting from C++, developers added the std library that contains the std::thread and from there you can do sleep for this thread compatible on any OS. So i can assume C not have any built-in function to make a sleep, you need to use a OS API function. You can have a similar effect using what IAmSupreme doing in his code, but this will waste 1 whole vcore from your CPU while the thread looping in the delay() function, so your CPU load will be high all the time for no reason
29th May 2024, 12:08 AM
john ds
john ds - avatar
+ 2
Yes there is, but doesn't not function as expected in soloLearn, check out the delay function in the code below https://sololearn.com/compiler-playground/cMMswSCLjU64/?ref=app
28th May 2024, 9:36 PM
IAmSupreme
IAmSupreme - avatar
0
In Python this is done with time.sleep(seconds). Most other languages also call it sleep, and Python is written in C++, so I would search for something similarly named.
28th May 2024, 8:11 PM
Wilbur Jaywright
Wilbur Jaywright - avatar