開発環境
- OS X Lion - Apple (UNIX) (OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- C (プログラミング言語)
- Clang (コンパイラ)
C実践プログラミング 第3版 (Steve Oualline (著)、 望月 康司 (監訳) (翻訳)、谷口 功 (翻訳)、オライリー・ジャパン)の7章(プログラミング手順)、7.15(プログラミング実習)、実習 7-2を解いてみる。
その他参考書籍
- プログラミング言語C 第2版 ANSI規格準拠 (B.W. カーニハン D.M. リッチー (著)、 石田 晴久 (翻訳)、共立出版)
- プログラミング言語Cアンサー・ブック 第2版 (クロビス・L.トンド、スコット・E.ギンペル(著)、矢吹 道郎(翻訳))
実習 7-2.
コード
sample.c
#include <stdio.h> #include <time.h> int main(int argc, char *argv[]) { struct tm tp1 = { 0, 0, 0, 6, 6 - 1, 1990 - 1900, }; struct tm tp2 = { 0, 0, 0, 3, 4 - 1, 1992 - 1900, }; time_t time1; time_t time2; double secs; int days; time1 = mktime(&tp1); time2 = mktime(&tp2); secs = difftime(time2, time1); days = (int) secs / (24 * 60 * 60); printf("%d日\n", days); return (0); }
makefile
CC=cc CFLAGS=-g sample: sample.c $(CC) $(CFLAGS) -o sample sample.c clean: rm -f sample
入出力結果(Terminal)
$ ./sample 667日 $
0 コメント:
コメントを投稿