2014年2月8日土曜日

開発環境

Head First C ―頭とからだで覚えるCの基本(David Griffiths (著)、Dawn Griffiths (著) 中田 秀基(監訳)(翻訳)、木下 哲也 (翻訳)、オライリージャパン)の6章(データ構造と動的メモリ)、コードマグネット(p.273)を解いてみる。

その他参考書籍

コードマグネット(p.273)

コード(BBEdit, Emacs)

sample273.c

#include <stdio.h>

typedef struct island{
    char *name;
    char *opens;
    char *closes;
    struct island *next;
} island;

island amity = {"アミティ", "09:00", "17:00", NULL};
island craggy = {"クラッギー", "09:00", "17:00", NULL};
island isla_nublar = {"イスラヌブラル", "09:00", "17:00", NULL};
island shutter = {"シャッター", "09:00", "17:00", NULL};

void display(island *start)
{
    island *i = start;
    for (; i != NULL; i = i->next) {
        printf("名前:%s 営業時間:%s-%s\n", i->name, i->opens, i->closes);
    }
}

int main(int argc, char *argv[])
{
    amity.next = &craggy;
    craggy.next = &isla_nublar;
    isla_nublar.next = &shutter;
    island skull = {"スカル", "09:00", "17:00", NULL};
    isla_nublar.next = &skull;
    skull.next = &shutter;
    
    display(&amity);
    return (0);
}

Makefile

sample273: sample273.c
 cc -g -o sample273 sample273.c

clean:
 rm sample273

入出力結果(Terminal)

$ make && ./sample273
cc -g -o sample273 sample273.c
名前:アミティ 営業時間:09:00-17:00
名前:クラッギー 営業時間:09:00-17:00
名前:イスラヌブラル 営業時間:09:00-17:00
名前:スカル 営業時間:09:00-17:00
名前:シャッター 営業時間:09:00-17:00
$

0 コメント:

コメントを投稿