A
Allie
How would I go about sorting this structure by title
typedef struct
char author[40]
char title[40]
char code[4]
int hold
int loan
} LIBRARY
LIBRARY book[N]
This is what I've written
void sortbytitle( LIBRARY *b, int n ) { /* n = number of books i
stoc
*
LIBRARY temp[N]
int i
for( i = 0; i < n; i++ )
if( strcmp( b.title, b[i + 1].title ) > 0 )
temp = b
b = b[i + 1]
b[i + 1] = temp
return
I get no errors or warnings when I compile using Bloodshed Dev-C++
However, my output then looks like this
AUTHOR TITLE CODE #COPY #BORR #AVAI
Golumbic Graph Theory G01 5 2
Jacobs Database Logic J01 3 1
Kanter Management Information K01 8 1
Kuo Numerical Methods K02 2 0
Habermann Operating Systems H01 10 5
Schroder C S01 7 2
Herzog Computing Structures H03 10 7
Holub Compiler Design H05 11 8
Galvin Operating Systems G02 15 2 1
Lane Data Communications L01 20 3 1
Kleinrock Queueing Systems K03 14 0 1
Kindred Data Systems K04 2 0
Horowitz Programming Languages H06 16 10
(Original output, before sort is called
AUTHOR TITLE CODE #COPY #BORR #AVAI
Habermann Operating Systems H01 10 5
Golumbic Graph Theory G01 5 2
Jacobs Database Logic J01 3 1
Kanter Management Information K01 8 1
Kuo Numerical Methods K02 2 0
Hughs Structured Programming H02 4 4
Schroder C S01 7 2
Herzog Computing Structures H03 10 7
Hunter Understanding C H04 6 6
Holub Compiler Design H05 11 8
Galvin Operating Systems G02 15 2 1
Lane Data Communications L01 20 3 1
Kleinrock Queueing Systems K03 14 0 1
Kindred Data Systems K04 2 0
Mano Computer Architecture M01 2 2
Horowitz Programming Languages H06 16 10
The sortbytitle() function is used in conjunction wit
printbyavail()... which explains the three missing books in the outpu
produced by sortybytitle().
The titles aren't sorted properly! What am I doing wrong
Thank you muchly :
--Alli
typedef struct
char author[40]
char title[40]
char code[4]
int hold
int loan
} LIBRARY
LIBRARY book[N]
This is what I've written
void sortbytitle( LIBRARY *b, int n ) { /* n = number of books i
stoc
*
LIBRARY temp[N]
int i
for( i = 0; i < n; i++ )
if( strcmp( b.title, b[i + 1].title ) > 0 )
temp = b
b = b[i + 1]
b[i + 1] = temp
return
I get no errors or warnings when I compile using Bloodshed Dev-C++
However, my output then looks like this
AUTHOR TITLE CODE #COPY #BORR #AVAI
Golumbic Graph Theory G01 5 2
Jacobs Database Logic J01 3 1
Kanter Management Information K01 8 1
Kuo Numerical Methods K02 2 0
Habermann Operating Systems H01 10 5
Schroder C S01 7 2
Herzog Computing Structures H03 10 7
Holub Compiler Design H05 11 8
Galvin Operating Systems G02 15 2 1
Lane Data Communications L01 20 3 1
Kleinrock Queueing Systems K03 14 0 1
Kindred Data Systems K04 2 0
Horowitz Programming Languages H06 16 10
(Original output, before sort is called
AUTHOR TITLE CODE #COPY #BORR #AVAI
Habermann Operating Systems H01 10 5
Golumbic Graph Theory G01 5 2
Jacobs Database Logic J01 3 1
Kanter Management Information K01 8 1
Kuo Numerical Methods K02 2 0
Hughs Structured Programming H02 4 4
Schroder C S01 7 2
Herzog Computing Structures H03 10 7
Hunter Understanding C H04 6 6
Holub Compiler Design H05 11 8
Galvin Operating Systems G02 15 2 1
Lane Data Communications L01 20 3 1
Kleinrock Queueing Systems K03 14 0 1
Kindred Data Systems K04 2 0
Mano Computer Architecture M01 2 2
Horowitz Programming Languages H06 16 10
The sortbytitle() function is used in conjunction wit
printbyavail()... which explains the three missing books in the outpu
produced by sortybytitle().
The titles aren't sorted properly! What am I doing wrong
Thank you muchly :
--Alli