/* Same as draw1, but uses getchar() instead of scanf(). */ #include int rgb[5][3] = { { 0, 0, 0 } , { 255, 255, 255 } , { 255, 0, 0 } , { 0, 255, 0 } , { 0, 0, 255 } } ; int main(void) { int col = 3; int x = 160; int y = 120; int c; /* note: not char! */ for (;;) { c = getchar(); if (c == EOF) return 0; switch (c) { case 'q': return 0; case '-': col = -1; break; case '0': col = 0; break; case '1': col = 1; break; case '2': col = 2; break; case '3': col = 3; break; case '4': col = 4; break; case 'l': if (x > 0) --x; break; case 'r': if (x < 319) ++x; break; case 'u': if (y > 0) --y; break; case 'd': if (y < 239) ++y; break; } if ((col >= 0) && (col < 5)) { printf("3 %d %d %d %d %d\n",x,y,rgb[col][0],rgb[col][1],rgb[col][2]); fflush(stdout); } } }