Head First C ―頭とからだで覚えるCの基本
(オライリージャパン)
David Griffiths (著) Dawn Griffiths (著)
中田 秀基(監訳)(翻訳) 木下 哲也 (翻訳)
開発環境
- OS X Yosemite - Apple (OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- C (プログラミング言語)
- LLVM/Clang (コンパイラ, Xcode - Apple)
Head First C ―頭とからだで覚えるCの基本(David Griffiths (著)、Dawn Griffiths (著) 中田 秀基(監訳)(翻訳)、木下 哲也 (翻訳)、オライリージャパン)の9章(プロセスとシステムサービス: 限界を超える)、コードマグネット(p.422)を解いてみる。
その他参考書籍
- 21st Century C: C Tips from the New School
- プログラミング言語C 第2版 ANSI規格準拠(B.W. カーニハンD.M. リッチー(著)、石田 晴久(翻訳)、共立出版)
- プログラミング言語Cアンサー・ブック 第2版 (クロビス・L.トンド、スコット・E.ギンペル(著)、矢吹 道郎(翻訳))
- C実践プログラミング 第3版(Steve Oualline(著)、望月 康司 (監訳)(翻訳)、谷口 功(翻訳)、 オライリージャパン)
コードマグネット(p.422)
コード(BBEdit, Emacs)
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <stopif.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 = 8;
char *phrase = argv[1];
for (int i = 0; i < times; i++) {
char *var;
asprintf(&var, "RSS_FEED=%s", feeds[i]);
char *vars[] = {var, NULL};
pid_t pid = fork();
Stopif(pid == -1, return 1, "プロセスをフォークできません: %s",
strerror(errno));
if (!pid)
Stopif(execle("/usr/bin/python", "/usr/bin/python", "rssgossip.py",
phrase, NULL, vars) == -1,
return 1, "スクリプトを実行できません: %s", strerror(errno))
}
}
入出力結果(Terminal)
$ make newshound clang ... $ ./newshound world > rss.txt $ cat rss.txt 20 most beautiful World Heritage Sites World's first heritage sites 10 of the world's most amazing long-distance trails Grape expectations: 'I want the world to drink Indian wine' And the world's best beach is ... CNN.com - World CNN.com - World How will the world end? World Press Photo Contest 2015 Monarchies around the world World War I in living color 15 of the world's most colorful landscapes 20 most beautiful World Heritage Sites And the world's safest city is... World's top 25 hotels The world's safest airlines $
0 コメント:
コメントを投稿