summaryrefslogtreecommitdiff
path: root/examples/c/getting_started/example_database_read.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/c/getting_started/example_database_read.c')
-rw-r--r--examples/c/getting_started/example_database_read.c17
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);
}