ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
HI When I try to compile my program this is the error that I am getting
Please note Iam still new to C.
DataBase.c: In function ‘main’:
DataBase.c:54: error: expected ‘while’ before ‘menu’
DataBase.c:173: error: expected declaration or statement at end of input
struct book_type {
unsigned date; //Coptright date
unsigned char ed; //edition
unsigned pages; //length of book
};
struct catalog {
char name[80]; //author name
char title[80]; //title
char pub[80]; //publisher
struct book_type book; //mechanical info
} cat[MAX];
int top = 0; //last location used
int main(void)
{
int choice;
load(); //read catalog
do {
choice = menu();
switch(choice) {
case 1: enter(); //enter books
break;
case 2: author_search(); //search by author
break;
case 3: title_search(); // search by title
break;
case 4: save();
break;
}
while(choice!=5);
return 0;
}
/*Return a menu selection */
menu(void)
{
int i;
char str[80];
printf("Card catalog.\n");
printf(" 1. Enter\n");
printf(" 2. Search by author.\n");
printf(" 3. Search by title.\n");
printf(" 4. Save catalog.\n");
printf(" 5. Quit");
do {
printf("Choose your selection: ");
gets(str);
i = atoi(str);
printf("\n");
} while(i<1 || i>5);
return i;
}
/*Enter books into database */
void enter(void)
{
int i;
char temp[80];
for(i=top; i<MAX; i++) {
printf("Enter author name Enter to quit): ");
gets(cat[i].name);
if(!*cat[i].name) break;
printf("Enter title: ");
gets(cat[i].title);
printf("Enter publisher: ");
gets(cat[i].pub);
printf("Enter Copyright date: ");
gets(temp);
cat[i].book.date = (unsigned) atoi(temp);
printf("Enter edition: ");
gets(temp);
cat[i].book.ed = (unsigned char) atoi(temp);
printf("Enter number of pages: ");
gets(temp);
cat[i].book.pages = (unsigned) atoi(temp);
}
top = i;
}
/*Search by author */
void search(void)
{
char name[80];
int i, found;
printf("Name: ");
gets(name);
found = 0 ;
for(i=0; i<top; i++)
if(!strcmp(name, cat[i].name)) {
display(i);
found = 1;
printf("\n");
}
do {
choice = menu();
switch(choice) {
case 1: enter(); //enter books
break;
case 2: author_search(); //search by author
break;
case 3: title_search(); // search by title
break;
case 4: save();
break;
}
while(choice!=5);
return 0;
}
Firstly, you didn't need to include all that code, only the relevant bit. Secondly, please use code tags to preserve indentation.
The problem appears to be that you're missing a curly brace (}). The one above your "while(choice != 5)" matches with the one on the line "switch(choice) {", so you need one to match with the do in your do while loop, i.e. do while loops look like this:
The error reported is generally encountered when there are syntax errors (like missing } and ; in the code). Using an IDE (like Eclipse) should help you zero in on the fix for such simple issues fast.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.