2014年11月9日日曜日

開発環境

Head First C ―頭とからだで覚えるCの基本(David Griffiths (著)、Dawn Griffiths (著) 中田 秀基(監訳)(翻訳)、木下 哲也 (翻訳)、オライリージャパン)の9章(プロセスとシステムサービス: 限界を超える)、コードマグネット(p.399)を解いてみる。

その他参考書籍

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

コード(BBEdit, Emacs)

sample399.c

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

char *now()
{
  time_t t;
  time (&t);
  return asctime(localtime (&t));
}

int main(int argc, char *argv[])
{
  char comment[80];
  char cmd[120];

  fgets(comment, 80, stdin);
  sprintf(cmd, "echo '%s' '%s' >> reports.log", comment, now());
  system(cmd);
  return 0;
}
  

Makefile

P=
CC=cc
CFLAGS=-g -Wall # -O3
SRC=
OBJ=
LDLIBS=

$(P): $(OBJ)
 $(CC) $(CFLAGS) $(LDLIBS) $(OBJ) -o $@


入出力結果(Terminal)

$ make sample399
cc -g -Wall     sample399.c   -o sample399
$ ./sample399
comment1
$ cat reports.log 
comment1
 Sun Nov  9 13:54:00 2014

$ ./sample399
comment2
$ cat reports.log 
comment1
 Sun Nov  9 13:54:00 2014

comment2
 Sun Nov  9 13:54:09 2014

$ 

0 コメント:

コメントを投稿