diff options
| author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2015-02-17 17:25:57 +0000 |
|---|---|---|
| committer | <> | 2015-03-17 16:26:24 +0000 |
| commit | 780b92ada9afcf1d58085a83a0b9e6bc982203d1 (patch) | |
| tree | 598f8b9fa431b228d29897e798de4ac0c1d3d970 /examples/c/getting_started/example_database_read.c | |
| parent | 7a2660ba9cc2dc03a69ddfcfd95369395cc87444 (diff) | |
| download | berkeleydb-master.tar.gz | |
Diffstat (limited to 'examples/c/getting_started/example_database_read.c')
| -rw-r--r-- | examples/c/getting_started/example_database_read.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/examples/c/getting_started/example_database_read.c b/examples/c/getting_started/example_database_read.c index 79a9fc2c..0e8486ff 100644 --- a/examples/c/getting_started/example_database_read.c +++ b/examples/c/getting_started/example_database_read.c @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2004, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2015 Oracle and/or its affiliates. All rights reserved. */ #include "gettingstarted_common.h" @@ -72,6 +72,10 @@ main(int argc, char *argv[]) return (ret); } + /* + * Show either a single item or all items, depending + * on whether itemname is set to a value. + */ if (itemname == NULL) ret = show_all_records(&my_stock); else @@ -197,23 +201,33 @@ show_inventory_item(void *vBuf) char *category, *name, *sku, *vendor_name; char *buf = (char *)vBuf; + /* Get the price. */ price = *((float *)buf); buf_pos = sizeof(float); + /* Get the quantity. */ quantity = *((int *)(buf + buf_pos)); buf_pos += sizeof(int); + /* Get the inventory item's name */ name = buf + buf_pos; buf_pos += strlen(name) + 1; + /* Get the inventory item's sku */ sku = buf + buf_pos; buf_pos += strlen(sku) + 1; + /* + * Get the category (fruits, vegetables, desserts) that this + * item belongs to. + */ category = buf + buf_pos; buf_pos += strlen(category) + 1; + /* Get the vendor's name */ vendor_name = buf + buf_pos; + /* Display all this information */ printf("name: %s\n", name); printf("\tSKU: %s\n", sku); printf("\tCategory: %s\n", category); @@ -221,6 +235,7 @@ show_inventory_item(void *vBuf) printf("\tQuantity: %i\n", quantity); printf("\tVendor:\n"); + /* Return the vendor's name */ return (vendor_name); } |
