This program is executed from the dos shell.Input is given in
the form of parameter.Two parameters are accepted as input and stored
in argv.These values are then passed to variables m,c and i. The
location of the substring is searched and then printed.
#include < stdio.h >
#include < conio.h >
void main(int argc,char *argv[])
{
char *i,*m,*c;
clrscr();
if ( argc != 3)
{
printf("\n Invalid arguments ");
exit(0);
}
else
{
m=c=argv[1];
i=argv[2];
while(*c!='\0')
{
if (*m == *i)
{
m++;
i++;
if (*i=='\0')
{
printf("%4d",c-argv[1] +1);
c=m;
i=argv[2];
}
}
else
{
c++;
m=c;
i=argv[2];
}
}
}
} // main
No comments:
Post a Comment