#include "stdio.h"
#include "string.h"
#define N 10
struct Book
{ char name[100];
float price;
};
int instring(char *s1,char *s2); //s1若属于s2的字串,则返回1,否则返回0
int main()
{ struct Book books[N]={{"Fling in sky",23.0},{"I love my mother",15.5},{"My love",25.6},{"Color is red",34.9},{"Black and red",20.5},{"Let me love you",16.0}, {"Sun is red",45.0},{"Flower sunshine",23.8},{"Say love not easy",45.9},{"Friday black",34.0}};
int i;
char name[20];
gets(name);
for(i=0;i<N;i++)
if(instring(name,books[i].name))
printf("%30s,%6.2f\n",books[i].name,books[i].price);
return 0;
}
int instring(char *s1,char *s2)
{
请在次插入你的代码
}
以上是题目要求,而我们要做的只是查询字符串之间是否是子串即可,对此我们要用到一个库函数strstr,先看一下它的参数
由信息可知,当查询成功将会返回子串首次出现的地址,如果失败咋返回一个null,故编写插入代码如下:
return strstr(s2,s1)==NULL?0:1;