/* Example 15.1: Simple actions with pointers Author: Peter Brusilovsky */ #include struct point { int x; int y; }; struct point readpoint(char *prompt); main(){ struct point pbase, p; int i; /* get base point */ pbase = readpoint("Enter base point"); /* get and check points */ for (i = 1; i <= 5; ++i) { p = readpoint("Enter point"); if (p.y > pbase.y) printf("The point (%d, %d) is above (%d, %d)\n", p.x, p.y, pbase.x, pbase.y); else if (p.y < pbase.y) printf("The point (%d, %d) is under (%d, %d)\n", p.x, p.y, pbase.x, pbase.y); else printf("(%d, %d) is on the same level with (%d, %d)\n", p.x, p.y, pbase.x, pbase.y); } return 0; } /* readpoint: reads a point and returns it */ struct point readpoint(char *prompt) { struct point input; printf("%s (x y):", prompt); scanf("%d %d", &(input.x), &(input.y)); return input; }