Head First C ―頭とからだで覚えるCの基本
(オライリージャパン)
David Griffiths (著) Dawn Griffiths (著)
中田 秀基(監訳)(翻訳) 木下 哲也 (翻訳)
開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- C (プログラミング言語)
- Clang (コンパイラ)
Head First C ―頭とからだで覚えるCの基本(David Griffiths (著)、Dawn Griffiths (著) 中田 秀基(監訳)(翻訳)、木下 哲也 (翻訳)、オライリージャパン)の7章(高度な関数)、コードマグネット(p.313)を解いてみる。
その他参考書籍
- プログラミング言語C 第2版 ANSI規格準拠 (B.W. カーニハン D.M. リッチー (著)、 石田 晴久 (翻訳)、共立出版)
- プログラミング言語Cアンサー・ブック 第2版 (クロビス・L.トンド、スコット・E.ギンペル(著)、矢吹 道郎(翻訳))
- C実践プログラミング 第3版 (Steve Oualline (著)、 望月 康司 (監訳) (翻訳)、 谷口 功 (翻訳)、 オライリージャパン)
コードマグネット(p.313)
コード(BBEdit, Emacs)
sample313.c
#include <stdio.h> #include <string.h> int NUM_ADS = 7; char *ADS[] = { "William: SBM GSHO likes sports, TV, dining", "Matt: SUM NS likes art, movies, theater", "Luis: SLM ND likes books, theater, art", "Mike: DWM DS likes trucks, sports and bieber", "Peter: SAM likes chess, working out and art", "Josh: SJM likes sports, movies and theater", "Jed: DBM likes theater, books and dining" }; void find() { int i; puts("検索結果:"); puts("------------------------------------"); for (i = 0; i < NUM_ADS; ++i) if (strstr(ADS[i], "sports") && !strstr(ADS[i], "bieber")) printf("%s\n", ADS[i]); puts("------------------------------------"); } int main(int argc, char *argv[]) { find(); return (0); }
Makefile
all: sample289 sample289: sample289.o sample287header.o cc -g -o sample289 sample289.o sample287header.o sample289.o: sample289.c sample287header.h cc -c sample289.c sample287header.o: sample287header.c sample287header.h cc -c sample287header.c
入出力結果(Terminal)
$ make && ./sample313 cc -g -o sample313 sample313.c 検索結果: ------------------------------------ William: SBM GSHO likes sports, TV, dining Josh: SJM likes sports, movies and theater ------------------------------------ $
0 コメント:
コメントを投稿