program in linux in C language, use arguments. Submit your solution as a plain-t
ID: 3790417 • Letter: P
Question
program in linux in C language, use arguments.
Submit your solution as a plain-text file with a .c extension in the name.
Name
timer - counts down to zero from a user supplied number.
Description
Displays a count down to zero from a number supplied by the user at the command line. Supports
pausing and unpausing the countdown. Countdown is done by ones, one second at a time. While
the program is runnng, typing p will pause the countdown and typing u will unpause it. echoing of
characters is disabled while the program is running.
Sample Usage
timer 60 begins the countdown
Hints
man 3 sleep
uses struct termios
uses VSTART and VSTOP
A 10-Point Sample Run
At 57 seconds left, I hit "p":
60
59
58
57
This paused the countdown output. Then, I hit "u" to resume the countdown :
60
59
58
57
56
55
54
53
52
51
so on...
Notice : in neither screen shot do you see the character "p" or the character "u". That's because echo is turned off for the duration of the program.
Explanation / Answer
#include <stdio.h>
#include <conio.h>
int main()
{
char c;
printf("Enter intital number")
int n;
scanf("%d", &n);
int play = 1;
while(1){
if(kbhit()){
c = getch();
if(c=='u'){
play = 1;
}else if(c=='p'){
play = 0;
}
}
// when n becomes 0 it will stop printing
if(n){
break;
}
if(play){
printf(n--);
}
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.