Skip to content

Instantly share code, notes, and snippets.

@dayt0n
Created December 28, 2015 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dayt0n/f56f60b44a8ac31df510 to your computer and use it in GitHub Desktop.
Save dayt0n/f56f60b44a8ac31df510 to your computer and use it in GitHub Desktop.
timer written in C for my Advanced Computing class
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char* argv[]) {
int time = 1;
if (argc > 2) {
printf("Too many arguments.\nusage: %s <end time in seconds>\n",argv[0]);
exit(0);
}
if (argc == 2) {
if(strcmp(argv[1],"-h") == 0 || strcmp(argv[1],"--help") == 0) {
printf("usage: %s <end time in seconds>\n",argv[0]);
return 0;
}
int quitTime = atoi(argv[1]);
for(int i = 0;i < quitTime;i++) {
system("clear");
printf("%d\n",i+1);
sleep(time);
}
return 0;
} else {
for(int i = 1;i > 0;i++) {
system("clear");
printf("%d\n",i);
sleep(time);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment