Alphabetical search/strncmp
My program is supposed to look through a library database by Author's last name,
but what I have gives out a single output each time.
Im in a class and I need guidance
Can you guys please help
I dont want to copy I want to understand what I'm doing
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 40 41 42 43 44 45 46 47
|
void list_by_name (Entry inventory[], int no_entries)
{
const int FIELD_DESCRIPTOR = 25;
const int FIELD_VALUE = 20;
char Search[][13] = {"Zzzzzzzzzz"};
int n;
AUTHOR_STRING author_name[13];
cout << "Enter Author's Last name: ";
cin >> Search[no_entries];
for (n = 0; n < no_entries; n++)
if(strncmp (author_name[n],Search[n], 1) == 0)
{
cout << left << setw(FIELD_DESCRIPTOR) << "Author's Last Name"
<< right << setw(FIELD_VALUE)<< inventory[n].author_name << EOLN;
cout << left << setw(FIELD_DESCRIPTOR) << "Author'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"
<< right << setw(FIELD_VALUE)<< inventory[n].quantity << EOLN;
return;
}
else if(strncmp (author_name[n],Search[n], 1) == 0)
{
cout << endl;
}
return;
}
|
bump please help
Topic archived. No new replies allowed.