I am working on an event-driven project that draws shape on an x-window. Whenever I click a mouse on the screen, new values of x and y are generated. My question is: how can I store the different values of x and y in the code below assuming each time you click a mouse, new values of x and y are generated.
int x, y;
x = report.xbutton.x;
y = report.xbutton.y;
if (report.xbutton.button == Button1) {
XFillArc(display_ptr, win, gc_red,
x - win_height/80, y - win_height/80,
win_height/60, win_height/60, 0, 360*64);
}
One version of the code might be:
Then your code would do:
where somewhere you have a variable:
Note that the
add_point()
function usesrealloc()
to do both the initial memory allocation and incremental memory allocations. The code uses a C99 compound literal to assign the valuesx
andy
to the nextPosition
in the array. If you don't have C99, you'll need to do two separate assignments.The
zap_posnlist()
function releases a previously initializedPosnList
. You might still need a formal initializer function — unless you're happy to use thePosnList xxx = { 0, 0, 0 };
notation everywhere.This code has now been sanitized by GCC; the original edition was not and there were bugs in it — bugs that generated compiler errors.
Tested code — note that
"stderr.h"
is not a standard header but is the error reporting code I habitually use. It provides theerr_error()
anderr_setarg0()
functions.Contact me (see my profile) if you want source for
stderr.h
andstderr.c
.