2015年5月27日水曜日

開発環境

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

その他参考書籍

エクササイズ(p.417)

コード(BBEdit, Emacs)

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

int main(int argc, char **argv) {
  char *feeds[] = {"http://rss.cnn.com/rss/edition.rss",
                   "http://rss.cnn.com/rss/edition_world.rss",
                   "http://rss.cnn.com/rss/edition_africa.rss",
                   "http://rss.cnn.com/rss/edition_americas.rss",
                   "http://rss.cnn.com/rss/edition_asia.rss",
                   "http://rss.cnn.com/rss/edition_europe.rss",
                   "http://rss.cnn.com/rss/edition_meast.rss",
                   "http://rss.cnn.com/rss/edition_us.rss"};
  int times = 3;
  char *phrase = argv[1];
  for (int 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;
    }
  }
}

入出力結果(Terminal)

$ gmake newshound
clang ...
$ ./newshound US
Russia displays military might
Suspect: 'Obsession to kill' became realistic
Australia threatens citizenship of jihadis
This is what tennis used to look like
Giant kangaroo stalks Australian suburb
20 of the world's top museums
Invention that changed music
The most dangerous biker gangs in the U.S.
Russia conducts military exercise in northwest
Why the war in Iraq just won't go away
Stunning images: Chinese houses laid bare
Are beheadings terrorizing us all?
$

0 コメント:

コメントを投稿