Reputation: 33
struct library{
int id;
int qty;
char name[50];
};
int SearchBookID(const struct library b[],int SearchID,int start,int end)
{
if(start<end && b[start].id == SearchID)
{
printf("%s %d %d",b[start].name,b[start].id,b[start].qty);
return 1;
}
else
{
SearchBookID(b,SearchID,end,start++);
}
}
void main()
{
int choice;
char ans;
int SeID;
printf("Welcome to the Library.\n");
do
{
printf("Please choose an option:\n");
printf("1.Insert a book\n");
printf("2.Delete a book by ID\n");
printf("3.Search a book by ID\n");
printf("4.Search a book by name\n");
printf("5.Display all books (sorted by name)\n");
printf("6.Display all books (unsorted)\n");
scanf("%d",&choice);
switch (choice){
case 1:
break;
case 2:
break;
case 3:
printf("please enter book ID:");
scanf("%d",&SeID);
SearchBookID(struct library b[],SeID,0,50);
break;
case 4:
break;
case 5:
break;
case 6:
break;
default:
printf("Invalid Choice. Please try again.\n");
break;
}
printf("do you want to choose another option?(y/n) ");
scanf(" %c",&ans);
}while(ans == 'y');
}
I keep getting these two errors and I don't understand why, especially the 'too few arguments' error. I tried to define the structure as global variable with 'typedef' but still the error persist and when I add more arguments to the function it still says 'too few arguments'. Anybody can help.
Upvotes: 0
Views: 366
Reputation: 311146
This call
SearchBookID(struct library b[],SeID,0,50);
^^^^^^^^^^^^^^^^^^
is incorrect. Instead of supplying an expression as the first function argument you wrote a declaration.
Compare this record with the function call inside the function itself
SearchBookID(b,SearchID,end,start++);
Pay attention to that nowhere in the program you declared an array with the element type struct library
.
Upvotes: 3