Hey everyone, long time no speak....
I was reading Adrian's tutorial on the win32 console, and goofing around, and just wanted to make a program that would randomly plant characters on the screen, here's what I came up with:
The whole cursor position thing works fine, and the reason I put the variable count in the printf line is so I could see why it wasn't working...when I compile it as it stands now, it prints "49Done" on a random place on the screen. The good news is it's a random place everytime I start the program, however, I wanted 49 different random spots, for instance I had it to where it was "printf("*"); so I wanted 49 "*" 's on different parts of the screen, but I changed it to print COUNT so I could see what was going on, you would think right now it would print "1", <new random position>, "2", <new rand pos>....etc, but nope, it's just "49Done".....and I'm like, "what the heck happened to the other 48??, lol!"....Code:#include <stdio.h> #include <windows.h> #include <stdlib.h> typedef struct COORD { short X; short Y; }; short A; short B; int main() { int count; HANDLE hOut; COORD position; for (count = 0; count < 50; count++) { hOut = GetStdHandle(STD_OUTPUT_HANDLE); srand(time(NULL)); A = 1 + (rand() % 40); B = 1 + (rand() % 40); position.X = A; position.Y = B; SetConsoleCursorPosition(hOut, position); printf("%d", count); //count is for debugging... } printf("Done"); getchar(); }
Thanks a lot,
Ash



LinkBack URL
About LinkBacks
....


