文字列内のキーワードの検索


次のテキストのセットからoutを含む行を検索します.
#include
#define MAX 1000

int  Getline(char S[],int sum);
int Search(char S[], char mou[]);
char mou[] = "out" ;

int main()
{
    int found = 0;
    char S[MAX];
    while (Getline(S, MAX) > 0)
        if (Search(S, mou)>0)
        {
            printf("%s", S);
            found++;
        }
    return found;
}


int  Getline(char S[], int sum)
{
    int i=0,c;
    while (--sum > 0&&(c=getchar ())!=EOF&&c!='
'
) S[i++] = c; if (c == '
'
) S[i++] = c; S[i] = '\0'; return i; } int Search(char S[], char mou[]) { int i, j, k; for (i = 0; S[i] != '\0'; i++) { for (j = i, k = 0; mou[k] != '\0'&&S[j] == mou[k]; j++, k++) ; if (k > 0 && mou[k] == '\0') { printf("find this!
"
); return i; } } return -1; }