|
[root@localhost c]# gcc match_char.c
/tmp/ccONSwnZ.o: In function `main':
/tmp/ccONSwnZ.o(.text+0x1b): the `gets' function is dangerous and should not be used.
[root@localhost c]# cat match_char.c
#include <stdio.h>
#include <string.h>
main()
{ char a[80],b[40];
int na,nb,i,j,flag;
gets(a);
gets(b);
na=strlen(a),nb=strlen(b);
flag = -1;
for (i=0;na-i >= nb;i++)
{
flag = -2;
for (j=0;j<nb;j++)
if (a[i+j] != b[j])
{ flag=-1;break;}
if(flag == -2)
{ flag=i+1;break;}
}
printf ("%s\n%s\n%d\n",a,b,flag);
}
[root@localhost c]# |
|