We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
hi, I am new to c programming. The following codes are compilable but there are a lot of errors. My main concern is that the display _all_infomration function would not work at all. Can someone kindly look at my codesand explain to me why? I have been buring midnight oil to look at them but i still cannot find the errors! Thanks a lot! #include <stdio.h> #include <string.h> #include <stdlib.h> #include <float.h> //initialisation struct book_record { char ISBN[11]; char title[31]; char author[31]; char category[3]; char date[11]; float price; }; struct BkArray { struct book_record BookArray[10]; }; //function prototypes void add_records(BkArray *library); void display_all_records(BkArray *library); void display_information(char *ISBN, BkArray *library); void display_books(BkArray *library); void delete_records(char *title, BkArray *library); void BarLine(int num); main() { //variables int quit,choice; char ISBN[11]; /*This ISBN refers to the input by the finder*/ char title[31]; char menu; BkArray library; BkArray *lib; for (int i = 0; i != 9; i++) { strcpy(library.BookArray[i].title, "NULL" ); strcpy(library.BookArray[i].author, "NULL" ); strcpy(library.BookArray[i].category, "NULL" ); strcpy(library.BookArray[i].date, "NULL" ); strcpy(library.BookArray[i].ISBN, "NULL" ); library.BookArray[i].price = 0.00; } do{ printf("\n"); BarLine(30); printf("\tMENU\n"); BarLine(30); printf("1 - Add new records.\n"); printf("2 - Display all book records.\n"); printf("3 - Find and display book information given the ISBN.\n"); printf("4 - Find all books written by a particular author.\n"); printf("5 - Delete book record given the title.\n"); printf("6 - Quit\n"); printf("\nEnter your choice: "); scanf("%d", &choice); lib = &library; switch(choice) { case 1: add_records(lib); break; case 2: display_all_records(lib); break; case 3: printf("\nEnter ISBN: "); scanf("%s", ISBN); display_information(ISBN, lib); break; case 4: display_books(lib); break; case 5: printf("\nEnter title: "); gets( title); delete_records(title,lib); break; case 6: quit = 1; break; default: printf("\nThere is no such choice.\n"); } }while(quit== 0); return 0; } void BarLine(int num) { for(int l = 0; l < num; l++) printf("="); printf("\n"); }//BarLine //Add book records in Book Array void add_records(BkArray* library) { //variables int number; char buf[10]; printf("\nEnter the number of records that you are going to enter: "); scanf("%d", &number); // clscr(); for( int k = 0; k < number; k++) { printf("\n#%d Record:\n", k+1); BarLine(30); printf("Enter ISBN: "); gets( library->BookArray[k].ISBN); gets( library->BookArray[k].ISBN); printf("Enter the title of the book: "); gets( library->BookArray[k].title); printf("Enter the author of the book: "); gets(library->BookArray[k].author); printf("Enter the price of the book: "); gets(buf); library->BookArray[k].price = (float) atof(buf); printf("Enter the category of the book: "); gets( library->BookArray[k].category); printf("Enter the published date in the format of dd/mm/yyyy: "); gets (library->BookArray[k].date); }//for }//add_records //Display all book records void display_all_records(BkArray *library) { for (int p = 0; p < sizeof(library); p++) { printf("\n#%d Record:\n", p+1); BarLine(30); printf("ISBN: %s.\n", library->BookArray[p].ISBN); printf("Title: %s.\n", library->BookArray[p].title); printf("Author: %s.\n", library->BookArray[p].author); printf("Price: %.2f.\n", library->BookArray[p].price); printf("Category: %s.\n", library->BookArray[p].category); printf("Published Date: %s.\n", library->BookArray[p].date); }//for }//display_records // Find and display book information given the IBSN void display_information(char *ISBN, BkArray *library) { int cnt = 0; for (int q = 0; q < sizeof(library); q++) { if (strcmp(library->BookArray[q].ISBN,ISBN)== 0) { printf("Book Found!\n"); printf("ISBN: %s.\n", ISBN); printf("Title: %s.\n", library->BookArray[q].title); printf("Author: %s.\n", library->BookArray[q].author); printf("Price: %.2f.\n", library->BookArray[q].price); printf("Category: %s.\n", library->BookArray[q].category); printf("Published Date: %s.\n", library->BookArray[q].date); cnt++; }//if }//for if(cnt == 0) printf("Book cannot be found!"); }//display_information //find all books written by a particular author void display_books(BkArray *library) { //variable char author1[31]; int cnt = 0; printf("\nEnter author: "); gets(author1); for(int r = 0; r < sizeof(library); r++) { if(strcmp(library->BookArray[r].author, author1)== 0) { printf("The title of the book is %s.\n", library->BookArray[r].title); cnt++; break; } }//for if(cnt != 1) printf("No Book is found!"); }//display_book //Delete book record given the title void delete_records(char *title, BkArray *library) { for (int i = 0; i < sizeof(library->BookArray); i++) { if(strcmp(library->BookArray[i].title, title)== 0) { for (int j = i; j < sizeof(library->BookArray); j++) strcpy(library->BookArray[j].title, library->BookArray[j++].title); strcpy(library->BookArray[j].ISBN, library->BookArray[j++].ISBN); strcpy(library->BookArray[j].author, library->BookArray[j++].author); strcpy(library->BookArray[j].date, library->BookArray[j++].date); strcpy(library->BookArray[j].category, library->BookArray[j++].category); library->BookArray[j].price = library->BookArray[j++].price; }//if }//for }//delete_record