输入两个字符串,验证其中一个串是否为另一个串的子串。 输入描述: 两行,每行一个字符串。 输出描述: 若第一个串 s1是第二个串 s2 的子串,则输出(s1) is substring of (s2); 否则,若第二个串 s2 是第一个串 s1 的子串,输出(s2) is substring of (s1); 否则,输出 No substring。
#include<stdio.h>
#include<string.h>
int main()
{
char a[100];
char b[100];
int i=0;
int j=0;
while(char a[100]!='\0'){
scanf("%c",&a[i]);
i++;
}
while(char b[100]!='\0'){
scanf("%c",&b[j]);
j++;
}
char *p=strstr(a,b);
char *p1=strstr(b,a);
if(p==NULL){
if(p1==NULL){
printf("No shbstring\n");
}else
printf("%s is substring of %s",&b[100],&a[100]);
}else
printf("%s is substring of %s",&a[100],&b[100]);
return 0;
}