/*
・・・Q・・・・・・・・・・・Z・p・メ・・・ア ・ス・ャ5・N・x・E・t・・・E・゚・・ ・・18・i・ン・・・P・j
BohYoh Shibata PREPARATION
*/
#include <stdio.h>
#define MAXLINE 256
int search(char *, char *);
main()
{
int n;
char file[32], pattern[MAXLINE], buffer[MAXLINE];
FILE *fp ;
puts("File name ?");
gets(file);
puts("Pattern ?");
gets(pattern);
if ((fp = fopen(file, "r")) != NULL) {
for (n = 1; fgets(buffer, MAXLINE, fp) != NULL; n++ )
if (search(buffer, pattern) >= 0)
printf("%4d:%s", n, buffer);
fclose(fp);
} else
fprintf(stderr, "%s: open error\n", file);
}
int search(char *b, char *p)
{
int n, s, t;
for (n = 0; b[n] != '\0'; n++) {
for (s = n, t = 0; b[s] == p[t] && p[t] != '\0'; s++, t++);
if ( p[t] == '\0' )
return n;
}
return -1;
}