2013年10月11日金曜日

開発環境

C実践プログラミング 第3版 (Steve Oualline (著)、 望月 康司 (監訳) (翻訳)、谷口 功 (翻訳)、オライリー・ジャパン)の7章(プログラミング手順)、7.15(プログラミング実習)、実習 7-3を解いてみる。

その他参考書籍

実習 7-3.

コード

sample.c

#include <stdio.h>
int main(int argc, char *argv[])
{
    int cps;
    int bpd, bph, bpm, bps;
    int days, hours, mins;
    double secs;
    int s;
    char line[100];
    cps = 960;
    bps = cps * 1;
    bpm = bps * 60;
    bph = bpm * 60;
    bpd = bph * 24;
    printf("ファイルサイズを入力(バイト): ");
    fgets(line, sizeof(line), stdin);
    sscanf(line, "%d", &s);
    days = s / bpd;
    s %= bph;
    hours = s / bph;
    s %= bph;
    mins = s / bpm;
    s %= bpm;
    secs = s / (double) bps;
    printf("ファイルの内容を転送するために要する時間: %d日%d時間%d分%lf秒\n",
        days, hours, mins, secs);
    return (0);
}

makefile

CC=cc
CFLAGS=-g

sample: sample.c
 $(CC) $(CFLAGS) -o sample sample.c

clean:
 rm -f sample

入出力結果(Terminal)

$ make
cc -g -o sample sample.c
$ ./sample
ファイルサイズを入力(バイト): 419430400
ファイルの内容を転送するために要する時間: 5日0時間21分46.666667秒
$

0 コメント:

コメントを投稿