Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: doremi/countdown
base: 6b2ff18588
...
head fork: doremi/countdown
compare: 4affa4df58
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 33 additions and 22 deletions.
  1. +3 −3 countdown.c
  2. +30 −19 percent.c
View
6 countdown.c
@@ -7,7 +7,7 @@ int main()
time_t t = time(NULL);
time_t fut;
- gmtime_r(&t, &now);
+ localtime_r(&t, &now);
future = now;
future.tm_year = 112;
@@ -19,8 +19,8 @@ int main()
double diff = difftime(fut, t);
unsigned int day = (diff / 86400) + 1;
- printf("%d/%d/%d %d:%d\n", now.tm_year+1900, now.tm_mon+1, now.tm_mday, now.tm_min, now.tm_sec);
- printf("%f seconds\n", diff);
+ printf("%d/%02d/%02d %02d:%02d:%02d\n", now.tm_year+1900, now.tm_mon+1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec);
+ printf("%.0f seconds\n", diff);
printf("%d days\n", day);
return 0;
}
View
49 percent.c
@@ -6,36 +6,47 @@
diff2 = now - begin
*/
-int main()
+void init_tm(struct tm *t, int mon, int day, int hour, int min)
{
- struct tm begin, end, now;
+ struct tm now;
time_t now_t = time(NULL);
- time_t begin_t, end_t;
-
gmtime_r(&now_t, &now);
- begin = end = now;
+ *t = now;
+
+ t->tm_year = 112;
+ t->tm_mon = mon-1;
+ t->tm_mday = day;
+ t->tm_hour = hour;
+ t->tm_min = min;
+ t->tm_sec = 0;
+}
- begin.tm_year = 112;
- begin.tm_mon = 1;
- begin.tm_mday = 10;
- begin.tm_hour = 20;
- begin.tm_min = begin.tm_sec = 0;
+double percent(struct tm *begin, struct tm *end)
+{
+ struct tm now;
+ time_t now_t = time(NULL);
+ time_t begin_t, end_t;
- end.tm_year = 112;
- end.tm_mon = 1;
- end.tm_mday = 12;
- end.tm_hour = 16;
- end.tm_min = end.tm_sec = 0;
+ gmtime_r(&now_t, &now);
- begin_t = mktime(&begin);
- end_t = mktime(&end);
+ begin_t = mktime(begin);
+ end_t = mktime(end);
double diff1 = difftime(end_t, begin_t);
double diff2 = difftime(now_t, begin_t);
double percent = diff2 / diff1 * 100.0;
- printf("%.10lf%%\n", percent);
+ return percent;
+}
+
+int main()
+{
+ struct tm begin, end;
+
+ init_tm(&begin, 2, 12, 16, 0);
+ init_tm(&end, 2, 17, 17, 0);
+
+ printf("%.10lf%%\n", percent(&begin, &end));
return 0;
}
-

No commit comments for this range

Something went wrong with that request. Please try again.