c - How can I access members in an array of structures that I passed into a function by value? -
#include <stdio.h> #include "inventorymanager.h" void displayinventory(const struct item items[], const int size) { printf("\n\n"); printf("inventory\n"); printf("=========================================\n"); printf("sku price quanity\n"); int index = 0; (index = 0; index < size; index++) { printf("%-10.0d %-10.2f %-10d\n", items[index].sku, items[index].price, items[index].quantity); } printf("=========================================\n"); }
i getting red underlining under "items" when try access structure values within array.
i have 3 files, inventorymanger.h, inventorymanager.c, shopping_lab_2.c ... struct called item created in shopping_lab_2.c, , function seeing on stack overflow made in inventorymanager.c.
i not sure how call function. program below works without errors or warnings:
struct item{ int sku; float price; int quantity; }; void displayinventory(const struct item items[], const int size) { printf("\n\n"); printf("inventory\n"); printf("=========================================\n"); printf("sku price quanity\n"); int index = 0; (index = 0; index < size; index++) { printf("%-10.0d %-10.2f %-10d\n", items[index].sku, items[index].price, items[index].quantity); } printf("=========================================\n"); } int main() { item items[2] = {1, 1.1, 10, 2, 2.2, 20 }; // initialization displayinventory(items, 2); return 0; }
output:
inventory ========================================= sku price quanity 1 1.10 10 2 2.20 20 =========================================
Comments
Post a Comment