...
Code Block | ||
---|---|---|
| ||
#include <stdio.h> #defineenum { INV_SIZE=20 20}; typedef struct { int item[INV_SIZE]; int length; } Inventory; int *getStock(Inventory iv); int main(void) { Inventory iv; size_t i; int *item; iv.length = 0; item = getStock(iv); for (i = 0; i < INV_SIZE; i++) { if (item[i] == 1) { printf("Almost out of stock of item: %d", i); } } return 0; } int *getStock(Inventory iv) { if (iv.length == 0) { return NULL; } else { return iv.item; } } |
...
Code Block | ||
---|---|---|
| ||
#include <stdio.h> #defineenum { INV_SIZE=20 20}; typedef struct { int item[INV_SIZE]; int length; } Inventory; int *getStock(Inventory iv); int main(void) { Inventory iv; size_t i; int *item; iv.length = 0; item = getStock(iv); for (i = 0; i < INV_SIZE; i++) { if (item[i] == 1) { printf("Almost out of stock of item: %d", i); } } return 0; } int *getStock(Inventory iv) { return iv.item; } |
...