473,563 Members | 2,767 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Debugging book search application - assignment

momotaro
357 Contributor
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 “SearchBySubjec t” 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 1501
sicarie
4,677 Recognized Expert Moderator Specialist
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
4798
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 human readable? ....and why are there no stack backtraces? When a problem arises, I am often interested in knowing where the
1
1495
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 managed dll(C#), which inturn is calling a native dll (c++). OK. Now in the VB.NET application, I also add the project of C3(dll). Now while debugging...
28
3137
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 linear search the best here(for loop from beginning to end of array)? It seems like some other search algorithm like binary or whatever would be of no...
0
3212
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 converted/developed with VB.NET. What I want from debugging is to be able to step into the methods in the DLLs called from ASP scripts using Visual Studio .NET. ...
6
2494
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 just go through each file/folder and right-click, selecting "Include in project". The IDE is nice in that it checks, verifies id tags, etc. What am...
13
9947
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 situation. Specifically should i use <arraylist> or a hashtable or is these a better way? Thank you all in advance. here is the assignment... sorry if...
5
7784
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 app.config file referencing arbitrary versions of the plug-in components they wish to consume. Here's the problem: Assuming I have installed any...
2
20828
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 some of the tools provided on the command-line. If you hate the command line tools, get over it since you’re bound to be using them at some point in your...
0
7665
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6255
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.