2014年7月16日水曜日

開発環境

Head First C ―頭とからだで覚えるCの基本(David Griffiths (著)、Dawn Griffiths (著) 中田 秀基(監訳)(翻訳)、木下 哲也 (翻訳)、オライリージャパン)の7章(高度な関数: 関数を最大限に活用する)、コードマグネット(p.313)を解いてみる。

その他参考書籍

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

コード(BBEdit, Emacs)

sample313.c

#include <stdio.h>
#include <string.h>

#include "sample313.h"

void find()
{
  int i;
  
  puts("検索結果:");
  puts("--------------------------------------------------");
  for (i = 0; i < NUM_ADS; ++i)
    if (strstr(ADS[i], "sport") && ! strstr(ADS[i], "bieber"))
      printf("%s\n", ADS[i]);
  puts("--------------------------------------------------");
}

int main(int argc, char *argv[])
{
  find();

  return (0);
}

Makefile

CC=cc
CFLAGS=-g -Wall
SRC=sample313.c
OBJ=sample313.o

all: sample313

sample313: sample313.o
 $(CC) $(CFLAGS) $(OBJ) -o sample313

sample313.o: sample313.h sample313.c
 $(CC) $(CFLAGS) -c sample313.c -o sample313.o

clear:
 rm -rf sample313 $(OBJ)

入出力結果(Terminal)

$ make
cc -g -Wall -c sample313.c -o sample313.o
cc -g -Wall sample313.o -o sample313
$ ./sample313 
検索結果:
--------------------------------------------------
William: SBM GSHO likes sports, TV, dining
Josh: SJM likes sports, movies and theater
--------------------------------------------------
$

0 コメント:

コメントを投稿