2014年3月26日水曜日

開発環境

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

その他参考書籍

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

コード(BBEdit, Emacs)

turtle.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

all: turtle

turtle: turtle.c
 cc -g -o turtle turtle.c

入出力結果(Terminal)

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

0 コメント:

コメントを投稿