初学者,有意者,帮帮我哦~
编写程序,输入两个字符串存入数组a和数组b中,判断数组b中字符串是否在数组a字符串中出现(称为子串)。若b串是a串的子串则输出“yes!”,否则输出 “no!”
好吧,我来试试……
程序代码:
#include <stdio.h>
int test(char *a, char *b)
{
int i=0,j=0;
while(a[i]!='\0')
{
if(a[i]==b[0])
break;
else
i++;
}
while(a[i]!='\0' && b[j]!='\0' && a[i]==b[j])
{
i++;
j++;
}
if(b[j]=='\0')
return 1;
else
return 0;
}
int main()
{
char a[20],b[20];
printf("输入数组:");
scanf("%s", a);
printf("输入数组:");
scanf("%s", b);
if(test(a, b))
printf("Yes");
else
printf("NO!");
return 0;
}









