September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
35
Task/Nautical-bell/C/nautical-bell.c
Normal file
35
Task/Nautical-bell/C/nautical-bell.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include<unistd.h>
|
||||
#include<stdio.h>
|
||||
#include<time.h>
|
||||
|
||||
#define DELAY 3000
|
||||
|
||||
int main(){
|
||||
int i,times;
|
||||
|
||||
time_t t;
|
||||
struct tm* currentTime;
|
||||
|
||||
while(1){
|
||||
time(&t);
|
||||
currentTime = localtime(&t);
|
||||
|
||||
times = (currentTime->tm_hour%12==0)?12:currentTime->tm_hour%12;
|
||||
|
||||
if(currentTime->tm_min==0 && currentTime->tm_sec==0){
|
||||
printf("\nIt is now %d:00 %s. Sounding the bell %d times.",times,(currentTime->tm_hour>11)?"PM":"AM",times);
|
||||
|
||||
for(i=0;i<times;i++){
|
||||
printf("\a");
|
||||
sleep(DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
else if(currentTime->tm_min==30 && currentTime->tm_sec==0){
|
||||
printf("\nIt is now %d:30 %s. Sounding the bell once.",times,(currentTime->tm_hour>11)?"PM":"AM");
|
||||
printf("\a");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue