#include <stdio.h>
#include <string.h>

enum { shelves = 2, per_shelf = 3 };

struct item {
    const char *name;
    int count;
};

struct shelf {
    const char *label;
    item items[per_shelf];
};

shelf store[shelves] = {
    { "fruit", { { "apple", 10 }, { "pear", 4 }, { "plum", 7 } } },
    { "veg", { { "carrot", 20 }, { "onion", 15 }, { "leek", 2 } } }
};

/* the count field of the item with this name, wherever it is */
int &find_var(const char *name)
{
    static int dummy;           /* returned when nothing is found */
    int i, j;

    for (i = 0; i < shelves; i++)
        for (j = 0; j < per_shelf; j++)
            if (strcmp(store[i].items[j].name, name) == 0)
                return store[i].items[j].count;
    dummy = 0;
    return dummy;
}

void print_store()
{
    int i, j;

    for (i = 0; i < shelves; i++) {
        printf("%-6s", store[i].label);
        for (j = 0; j < per_shelf; j++)
            printf("  %s=%d", store[i].items[j].name,
                   store[i].items[j].count);
        printf("\n");
    }
}

int main()
{
    print_store();

    int x = find_var("pear") + 5;       /* read:   x = 4 + 5 */
    find_var("plum") = 3;               /* assign: plum = 3 */
    find_var("carrot") *= 10;           /* carrot = 20 * 10 */
    find_var("leek")++;                 /* leek = 2 + 1 */
    int y = ++find_var("onion");        /* onion = 16, y = 16 */

    printf("\nx = %d, y = %d\n\n", x, y);
    print_store();
    return 0;
}
