開発環境
- OS: macOS High Sierra - Apple
- Text Editor: Emacs
- コンパイラー: LLVM/Clang, GCC(gcc)
- プログラミング言語: C
Head First C ―頭とからだで覚えるCの基本 (David Griffiths (著)、Dawn Griffiths (著)、中田 秀基 (監修)、木下 哲也 (翻訳)、オライリージャパン)の6章(データ構造と動的メモリ - 架け橋を築く)、コードマグネット(p. 273)を取り組んでみる。
コードマグネット(p. 273)
Makefile
CC = cc all: run sample: sample.c $(CC) sample.c -o sample run: sample ./sample
#include <stdio.h>
typedef struct Island Island;
void Island_display(Island*);
struct Island {
char *name;
char *opens;
char *closes;
struct Island *next;
};
void Island_display(Island *start) {
for (Island *i = start;i != NULL; i = i->next) {
printf("名前: %s 営業時間: %s-%s\n",
i->name, i->opens, i->closes);
}
}
int main() {
Island amity = {"アミティ", "09:00", "1:00", NULL};
Island craggy = {"クラッギー", "09:00", "17:00", NULL};
Island isla_nublar = {"イスラヌブラル", "09:00", "17:00", NULL};
Island shutter = {"シャッター", "09:00", "17:00", NULL};
amity.next = &craggy;
craggy.next = &isla_nublar;
isla_nublar.next = &shutter;
Island_display(&amity);
}
入出力結果(Terminal)
$ make cc sample.c -o sample ./sample 名前: アミティ 営業時間: 09:00-1:00 名前: クラッギー 営業時間: 09:00-17:00 名前: イスラヌブラル 営業時間: 09:00-17:00 名前: シャッター 営業時間: 09:00-17:00 $
0 コメント:
コメントを投稿