// structure, function & pointers #include // declare a structure with 3 members struct inventory{ int nPartNo; float fBuyCost; float fSellingPrice; }; // function prototypes, both will receive a pointer // to inventory structure void readpart(struct inventory *pPartPtr); void printpart(struct inventory *pPartPtr); void main(void) { // variable of type struct inventory struct inventory items; // print some info printf("[PART INVENTORY DATA]\n\n"); // call readpart() function, passing an address of items (structure) readpart(&items); // then, call printpart() function, passing an address of items (structure) printpart(&items); } // print the part info using the passed pointer void printpart(struct inventory *pPartPtr) { printf("\n[SUMMARY]\n"); printf("Part no. = %d, Buying Cost = $%6.2f, Retail price = $%6.2f\n", \ pPartPtr->nPartNo, pPartPtr->fBuyCost, pPartPtr->fSellingPrice); } // read & store part info in inventory structure // using the passed pointer to the inventory structure void readpart(struct inventory *pPartPtr) { // local variables int nPartNum; float fPrice; // prompt user for part number printf("Part Number: "); // read and store part number to nPartNum variable scanf("%d", &nPartNum); // assign nPartNum to nPartNo structure's member pPartPtr->nPartNo = nPartNum; // prompt user for buying cost printf("Buying Cost: $"); // read and store buying cost to fPrice variable scanf("%f", &fPrice); // assign fPrice to fBuyCost structure's member pPartPtr->fBuyCost = fPrice; // prompt user for retail price printf("Retail Price: $"); // read and store buying retail price to fPrice variable // we reuse fPrice variable because it is just a temporary storage scanf("%f", &fPrice); // assign fPrice to fSellingPrice structure's member pPartPtr->fSellingPrice = fPrice; }