473,395 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Debugging book search application - assignment

momotaro
357 100+
You are to write a card catalog type definition. There are up to 1000 books, and for each one you need:
Title
A list of up to 5 authors
Catalog number
A list of up to 5 subject headings
Status (checked out or in the library)
Write a function “SearchBySubject” that takes as parameters the database of books and a subject (string). It should find all books with that subject and print their title, first author, and catalog number.

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2.  
  3. typedef struct
  4. {
  5.     char title[20];
  6.     author author;
  7.     subject subject;
  8.     int cat_num;
  9.     char In_Out;
  10. }book;
  11.  
  12. typedef struct
  13. {
  14.     char author[20];
  15. }author;
  16.  
  17. typedef struct
  18. {
  19.     char subject[20];
  20. }subject;
  21.  
  22. void alloc_BookNum(int BookNum, book book_arr[]);
  23. void alloc_AuthNum(int AuthNum, author author_arr[]);
  24. void alloc_SubNum(int SubNum, subject subject_arr[]);
  25. void get_data(book *arr_book[]);
  26. void SearchBySubject(book arr_book[], char subject);
  27.  
  28.  
  29. void main()
  30. {
  31.     alloc_BookNum(BookNum, book_arr[]);
  32.     alloc_AuthNum(int AuthNum, author author_arr[]);
  33.     alloc_SubNum(int SubNum, subject subject_arr[]);
  34.     SearchBySubject(arr_book[], subject);
  35.     while(1);
  36. }
  37.  
  38. void alloc_BookNum(int BookNum, book book_arr[])
  39. {
  40.     book *book_arr;
  41.     printf("Enter the number of the books --> "); scanf("%d", &BookNum);
  42.     book_arr = (book*)calloc(BookNum, sizeof(book));
  43. }
  44.  
  45. void alloc_AuthNum(int AuthNum, author author_arr[])
  46. {
  47.     author *author_arr;
  48.     printf("Enter the number of the authors --> "); scanf("%d", &AuthNum);
  49.     author_arr = (author*)calloc(AuthNum, sizeof(author));
  50. }
  51.  
  52. void alloc_SubNum(int SubNum, subject subject_arr[])
  53. {
  54.     subject *subject_arr;
  55.     printf("Enter the number of subjects --> "); scanf("%d", &SubNum);
  56.     subject_arr = (subject*)calloc(SubNum, sizeof(subject));
  57. }
  58.  
  59.  
  60. void get_data(book book_arr[], author author_arr[], subject subject_arr[])
  61. {
  62.     int i, j, k;
  63.     for(i = 0; i < BookNum; i++)
  64.     {
  65.         printf("TITLE --> "); scanf("%s", book_arr[i].title);
  66.         for(j = 0; j < SubNum; j++)
  67.          {
  68.             printf("AUTHOR %d --> ", &AuthNum); scanf("%s", author_arr[j].author);
  69.          }
  70.         for(k = 0; k < SubNum ; k++)
  71.          {
  72.             printf("SUBJECT %d --> ", &SubNum); scanf("%s", subject_arr[k].subject);
  73.          }
  74.         printf("CATALOG NUMBER --> "); scanf("%d", &book_arr[i].cat_num);    
  75.         printf("STATUS(IN/OUT) --> "); scanf("%s", &book_arr[i].In_Out);
  76.     }
  77. }
  78.  
  79. void SearchBySubject(book book_arr[], char subject)
  80. {
  81.     char subject;
  82.     int i;
  83.     printf("ENTER YOUR SUBJECT --> "); scanf("%s", &subject);
  84.     for(i = 0; i < SubNum; i++)
  85.     {
  86.         if((strlen(book_arr[i].subject.subject[i])-strlen(subjet)) == 0)
  87.         {
  88.             if(strcmp(toupper(subject_arr[i].subject), toupper((subject))) == 0)
  89.             {
  90.                 prinf("TITLE --> %s", book_arr[i].title);
  91.                 printf("AUTHOR --> %s", book_arr[i].author.author[0]);
  92.                 printf("CATALOG NUMBER --> ", book_arr[i].cat_num);
  93.             }
  94.         }
  95.         else
  96.             printf("THERE IS NO RESULT MUCHING YOUR REQUEST !");
  97.     }
  98. }
Feb 11 '07 #1
1 1486
sicarie
4,677 Expert Mod 4TB
momotaro-

That looks like an interesting program, did you have a question about it? (ie, are you getting an error on the 'Search by Subject' function you provided? If so, what's the error, if not, what's your question?)
Feb 12 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

79
by: Tim Tyler | last post by:
PHP has some pretty funky error messages: "parse error, unexpected T_IF"; "Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING"; Humans often see these - shouldn't they be more...
1
by: Vishuonline | last post by:
Hi Folks, I have search on search engines for previous dicsussions dealing with this.. but didnt find em any useful... so here I am.. I am having a .NET (BV.NET) application. I am calling a...
28
by: joshc | last post by:
If I have an array of data that I know to be sorted in increasing order, and the array is less than 50 elements, and I want to find the first element greater than a certain value, is a simple...
0
by: ZMan | last post by:
Scenario: This is about debugging server side scripts that make calls to middle-tier business DLLs. The server side scripts are legacy ASP 3.0 pages, and the DLLs are managed DLLs...
6
by: KevinGPO | last post by:
I am currently developing a website in ASP (VBScript) using MS Visual C#.NET IDE. I just create a new "ASP.NET Web Application" and point to my local webserver (IIS) of my website address. Then I...
13
by: YoVoltron | last post by:
I am just starting this "appointment book" java program and would appreciate some basis direction. I do not expect anyone to write the code for me but i would like opinions on how to best handle the...
5
by: phnimx | last post by:
Hi , We have developed a number of plug-in .NET Library Components that we typically deploy with our various applications by installing them into the GAC. Each of the applications contains an...
2
jwwicks
by: jwwicks | last post by:
C/C++ Programs and Debugging in Linux This tutorial will give you a basic idea how to debug a program in Linux using GDB. As you are aware Visual Studio doesn’t run on Linux so you have to use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.