Question
Help with Strcmp! I have to, using the function strcmp, compare two books so , so it vcompares the section they belong to first, then
Help with Strcmp!
I have to, using the function strcmp, compare two books so , so it vcompares the section they belong to first, then the subsection, then the author, and then the tittle, and if they all coindide then the bood identifier. So int book_cmp(tBook b1, tBook b2) thats announces back 1 if b1>b2, 0 if b1=b2 and -1 if b1
This needs to be done in :
#include #include #include #include "books.h
int book_cmp(tBook b1, tBook b2) { int retVal=0; return retVal; }
data.h
* This code ensures that this file is included only once */ #ifndef __DATA_H #define __DATA_H /* If the constant DATA_H is not defined (ifndef), the code is added, otherwise, this code is excluded. When the code is added, the constant is defined, therefore next time this file will be included it will be defined and no inclusion will be done. */ #define MAX_PATHNAME 256 #define MAX_LINE 512 #define MAX_SECTIONS 10 #define MAX_SECTION_NAME 100 #define MAX_BOOKS 300 #define MAX_SUB 10 #define MAX_BOOK_AUTHOR_CODE 3 #define MAX_TITLE_LENGTH 100 #define MAX_ID_LENGTH 13 /* Definition of a boolean type */ typedef enum {FALSE, TRUE} tBoolean; /* Definition of the error type. */ typedef enum {OK=1, ERROR=0, ERR_CANNOT_READ=-1, ERR_CANNOT_WRITE=-2, ERR_MEMORY=-3, ERR_DUPLICATED_ENTRY=-4, ERR_INVALID_DATA=-5, ERR_ENTRY_NOT_FOUND=-6} tError; /* Definition of a location */ typedef struct { char row; char column; char shelf; } tLocation; /* Definition of a section */ typedef struct { char id; char name[MAX_SECTION_NAME]; tLocation init; } tSection; /* Table of sections */ typedef struct { tSection table[MAX_SECTIONS]; unsigned int size; } tSectionTable;
/* Definition of the book */ typedef struct {
//IDENTIFIER char identifier[MAX_ID_LENGTH];
//year published int yearPublished; //availability as boolean bool availability; //classification : [0] means a character identifier from main section //and [1] means a character identifier from subsection and both are the characters char classification[2]; //author code char authorCode[MAX_BOOK_AUTHOR_CODE]; //title char title[MAX_TITLE_LENGTH]; } tBook; /* Table of books */ typedef struct { tBook table[MAX_BOOKS]; unsigned int size; } tBookTable;
/* Definition of the application data structure */ typedef struct { /* Path where data will be stored */ char path[MAX_PATHNAME];
/* sections table */ tSectionTable sections;
/* Books table */ tBookTable books;
} tAppData; #endif /*__DATA_H*/
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started