Javatpoint Logo
Javatpoint Logo

Simple Stopwatch Program in C

In the following tutorial, we will create a C application for a digital stopwatch. The keyboard hit function is abbreviated as keyboardhit(). After pressing a key, it sends out a signal and outputs an integer that is not zero. There are four loops in this: the first loop counts hours, the second minutes, the third seconds, and the fourth loop maintains the speed of seconds (3 loop). Following the execution of this program, a signal is generated when a keyboard start key is hit. There is a variable (c) for storing a keyboard key; if c is equal to the p key, the wait function is called.


Another name for a thread is a lightweight process. By breaking a process up into several threads, parallelism is intended to be achieved. For instance, many tabs in a browser might represent various threads. Multiple threads are used by MS Word, including one for processing inputs and another for formatting the text. Below is a discussion of further advantages of multithreading.

Wait System Call

Until one of its child processes ends or a signal is received, a call to wait() pauses the caller process. Parent process continues to run after wait system call command after child process exits.

Child processes may end for any of the following reasons:

  • From main, it calls exit()
  • Returns (an int).
  • When a signal is received (by the OS or another process), its default response is to terminate.

Program for Simple Stopwatch


*#This is a stopwatch#*
**Press 'p' to pause.
**Press any key to start & to stop.

*#This is a stopwatch#*
Time-    0 : 7 : 784


We are awaiting the start (any key on the keyboard) key to be pushed while the thread is executing in the background. After hitting the any key, the thread again leaps to the thread join function; if the p key is pushed, the loops are all restarted with zeros; if the s key is touched, the thread jumps to the start label; and if the e key is pressed, the thread calls the exit() function, terminating the program.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA