## 2017年12月21日木曜日

### C - 高度な関数 - 関数を最大限に活用する(引数、関数ポインタ、変数)

Head First C ―頭とからだで覚えるCの基本 (David Griffiths (著)、Dawn Griffiths (著)、中田 秀基 (監修)、木下 哲也 (翻訳)、オライリージャパン)の7章(高度な関数 - 関数を最大限に活用する)、エクササイズ(p. 321)を取り組んでみる。

エクササイズ(p. 321)

コード

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

"William: SBM GSOH likes sports, TV, dining",
"Matt: SWM 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"
};

bool sports_or_workout(char *s)
{
return strstr(s, "sports") || strstr(s, "working out");
}

bool ns_theater(char *s)
{
return strstr(s, "NS") && strstr(s, "theater");
}

bool arts_theater_or_dining(char *s)
{
return strstr(s, "art") || strstr(s, "theater") || strstr(s, "dining");
}
void find(bool (*match)(char *s))
{
puts("検索結果");
puts("--------------------------------------------------");

for (size_t i = 0; i < 7; i++)
{
{
}
}
puts("--------------------------------------------------");
}

int main()
{
bool(*matches[])(char *s) = { sports_or_workout, ns_theater, arts_theater_or_dining, NULL };

for (size_t i = 0; matches[i] != NULL; i++)
{
find(matches[i]);
}

system("pause");
return 0;
}
```

```検索結果
--------------------------------------------------
William: SBM GSOH likes sports, TV, dining
Mike: DWM DS likes trucks, sports and bieber
Peter: SAM likes chess, working out and art
Josh: SJM likes sports, movies and theater
--------------------------------------------------

--------------------------------------------------
Matt: SWM NS likes art, movies, theater
--------------------------------------------------

--------------------------------------------------
William: SBM GSOH likes sports, TV, dining
Matt: SWM NS likes art, movies, theater
Luis: SLM ND likes books, theater, art
Peter: SAM likes chess, working out and art
Josh: SJM likes sports, movies and theater
Jed: DBM likes theater, books and dining
--------------------------------------------------

```