You are on page 1of 2

/*$$$$$$$$$$$$$$$$$$$$*/

#include<stdio.h>
#include<string.h>
void input(char filename[30]); /*$$$$$*/
int check(char string[100],char search[20],int p[20]);
main()
{
char filename[30];
printf("$$$$$$$$$$$$$$$$");
scanf("$$",filename);
input(filename);
getch();
}
void input(char filename[30])
{ FILE *fo;
int p[20],k,i,line=0,m=0,n=0,z,d;
char string[100],search[20],c,totsearch[30][20],comment[2];
fo=fopen(filename,"$");
comment[0]=getc(fo);
comment[1]=getc(fo);
if((comment[0]=='//')&&(comment[1]=='*'))
{ while(1)
{ comment[0]=getc(fo);
if(comment[0]=='*')
{ comment[1]=getc(fo);
if(comment[1]=='//')
{ totsearch[m][n]='\0';
n=0;m++;
break;
}
else
fseek(fo,-1L,1);
}
if((comment[0]==' ')||(comment[0]==',')||(comment[0]=='\n'))
{
totsearch[m][n]='\0';
n=0;m++;
}
else
{
totsearch[m][n]=comment[0];
n++;
}
}
}
for(i=0;i<m;i++)
printf("$$$$$",totsearch[i]);
do
{
k=0;
do
{ c=getc(fo);
string[k]=c;
k++;
}while((c!='\n')&&(c!=EOF));
string[k-1]='\0';
if(c!=EOF)
{ i=0;
while(i<m)

{ strcpy(search,totsearch[i]);
i++;
d=check(string,search,p);
if(d>0)
{ for(z=0;z<d;z++)
printf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",search,line,
p[z]);
}
}
line++;
}
}while(c!=EOF);
getch();
fclose(fo);
}
int check(char string[100],char search[20],int p[20])
{
int i,j,n,count=0;
n=strlen(search);
for(i=0;string[i]!='\0';i++)
{ for(j=0;search[j]!='\0';j++)
{ if(string[i+j]!=search[j])
break;
}
if(j==n)
{
p[count]=i;
count=count+1;
}
}
return count;
}

You might also like