2014年2月3日月曜日

開発環境

Head First C ―頭とからだで覚えるCの基本(David Griffiths (著)、Dawn Griffiths (著) 中田 秀基(監訳)(翻訳)、木下 哲也 (翻訳)、オライリージャパン)の5章(構造体、共用体、ビットフィールド)、自分で考えてみよう(p.239)を解いてみる。

その他参考書籍

自分で考えてみよう(p.239)

コード(BBEdit, Emacs)

sample239.c

#include <stdio.h>

typedef struct {
    const char *name;
    const char *species;
    int age;
} turtle;

void happy_birthday(turtle *t)
{
    (*t).age = (*t).age + 1;
    printf("誕生日おめでとう、%s!これで%i才ですね!\n",
        (*t).name, (*t).age);
}

int main(int argc, char *argv[])
{
    turtle myrtle = {"マ−トル", "長が目", 99};
    happy_birthday(&myrtle);
    printf("%sの年齢は%i才です。\n", myrtle.name, myrtle.age);
    return (0);
}

Makefile

sample239: sample239.c
 cc -g -o sample239 sample239.c

clean:
 rm sample239

入出力結果(Terminal)

$ make sample239 && ./sample239
cc -g -o sample239 sample239.c
誕生日おめでとう、マ−トル!これで100才ですね!
マ−トルの年齢は100才です。
$

0 コメント:

コメントを投稿