#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define M 100
struct data
{
int id;
char name[20];
double price;
}book[M];
//在有M个元素的结构体数组s中查找名为name的书,若找到,函数返回数组下标,否则,函数返回-1
int findbook(struct data s[], char name[])
{
int i;
for( i = 0;i<M;i++)
if(strcmp(s[i].name,name) == 0 )
return i;
return -1;
}
int main()
{
strcpy(book[2].name,"空间几何");
printf(" i is %d\n",findbook(book,"空间几何"));
return 0;
}