検索される文字列は埋め込みました(ふしぎの国のアリス 序文)
パラメータに検索文字列・・・細かい部分は未検証です。^^;
usr ~/test/cpp % ./a.out or
3
usr ~/test/cpp % ./a.out but
1
usr ~/test/cpp % ./a.out book
2
cpp
1#include <iostream>
2#include <cstring>
3
4using namespace std;
5
6static const char Alice[]="Alice was beginning to get very tired of sitting by her sister"
7"on the bank, and of having nothing to do: once or twice she had peeped into the"
8"book her sister was reading, but it had no pictures or conversations in it, ‘and what"
9" is the use of a book,’ thought Alice ‘without pictures or conversations?’";
10
11int find(const char *sptr)
12{
13 int ret= 0;
14 //
15 size_t pos= strlen(sptr);
16 char * cp= strstr(Alice,sptr);
17 while( cp ){
18 ret++;
19 cp += pos;
20 cp = strstr(cp,sptr);
21 }
22 return ret;
23}
24
25
26int main(int agc,char *agv[])
27{
28 if( agc != 2){
29 return 1;
30 }
31 //
32 int n= find(agv[1]);
33 cout << n << endl;
34 //
35 return 0;
36}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。