Alphabetical search / strncmp
Dec 3, 2014 at 9:51pm UTC
My program is supposed to look through a library database by Author's last name,
but what I have gives out no output every time I enter an author's name what am I doing wrong?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
void list_by_name (Entry inventory[], int no_entries)
{
const int FIELD_DESCRIPTOR = 25;
const int FIELD_VALUE = 20;
char Search[][13] = {"" };
int n;
cout << "Enter Author's Last name: " ;
cin >> Search[MAX_AUTHOR_NAME];
for (n = 0; n > 13; n++)
if (strncmp (Search[n],inventory[n].author_name, 9) == 0)
{
cout << left << setw(FIELD_DESCRIPTOR) << "Author's Last Name"
<< right << setw(FIELD_VALUE)<< inventory[n].author_name << EOLN;
cout << left << setw(FIELD_DESCRIPTOR) << "Autho's initial"
<< right << setw(FIELD_VALUE)<< inventory[n].author_initial << EOLN;
cout << left << setw(FIELD_DESCRIPTOR) << "Inventory Number"
<< right << setw(FIELD_VALUE)<< inventory[n].inventory_number << EOLN;
cout << left << setw(FIELD_DESCRIPTOR) << "Location"
<< right << setw(FIELD_VALUE)<< inventory[n].location << EOLN;
cout << left << setw(FIELD_DESCRIPTOR) << "Book Title"
<< right << setw(FIELD_VALUE)<< inventory[n].title << EOLN;
cout << left << setw(FIELD_DESCRIPTOR) << "Comment"
<< right << setw(FIELD_VALUE)<< inventory[n].comment << EOLN;
cout << left << setw(FIELD_DESCRIPTOR) << "Quantity"
}
else if (strncmp (Search[n],inventory[n].author_name, 9) == 0);
{
cout << endl;
}
return ;
Dec 3, 2014 at 11:38pm UTC
Please explain lines 5 and 9.
Topic archived. No new replies allowed.