2014年4月16日水曜日

開発環境

Head First C ―頭とからだで覚えるCの基本(David Griffiths (著)、Dawn Griffiths (著) 中田 秀基(監訳)(翻訳)、木下 哲也 (翻訳)、オライリージャパン)の9章(プロセスとシステムサービス)、エクササイズ(p.417)を解いてみる。

その他参考書籍

エクササイズ(p.417)

コード(BBEdit, Emacs)

newshound.c

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

int main(int argc, char *argv[])
{
  char *feeds[] = {"http://rss.cnn.com/rss/edition.rssl",
                   "http://rss.cnn.com/rss/edition_world.rss",
                   "http://rss.cnn.com/rss/edition_asia.rss"};
  int times = 3;
  char *phrase = argv[1];
  int i;
  
  for (i = 0; i < times; ++i) {
    char var[255];
    sprintf(var, "RSS_FEED=%s", feeds[i]);
    char *vars[] = {var, NULL};
    if (execle("/usr/bin/python", "/usr/bin/python", "rssgossip.py",
               phrase, NULL, vars) == -1) {
      fprintf(stderr, "スクリプトを実行できません:%s\n", strerror(errno));
      return (1);
    }
  }
  return (0);
}

Makefile

all: newshound

newshound: newshound.o
 cc -g -o newshound newshound.o

newshound.o: newshound.c
 cc -c -o newshound.o newshound.c
clean:
 rm -rf newshound

入出力結果(Terminal)

$ make && ./newshound japan
make && ./newshound japan
cc -c -o newshound.o newshound.c
cc -g -o newshound newshound.o
Japan's extreme giant zipper artist
$

0 コメント:

コメントを投稿