在下列一组文本中查找出含out的行:
#include<stdio.h>
#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!='\n')
S[i++] = c;
if (c == '\n')
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!\n");
return i;
}
}
return -1;
}