C-ben hogy írjak ki x-ekből egy nagy x-et?










Bár szerintem minden eszközt megadtunk, de tessék, itt egy másik ötlet: vegyél fel egy karaktertömböt, ami 80*25 hosszú. Ebbe rajzolj bele egy X-et (pl írhatsz egy gotoxy függvényt, ami visszaad egy char&-t, és így néz ki:
char& gotoxy(int x, int y)
{
return karakterTomb[x + y*80];
}
Ekkor csak ki kell írni a karakterTomb-t (std::cout.write(karakterTomb, 80*25), persze előtte rajzold bele az X-t.





Tessék, még be is comment-eltem :D
const int WIDTH = 80;
const int HEIGHT = 25;
char screenBuffer[WIDTH*HEIGHT];
void putChar(int x, int y, char c);
void drawBuffer();
void clearScreen();
int _tmain(int argc, _TCHAR* argv[])
{
// Init buffer
clearScreen();
// ******************************************
// Draw 5*5 big X in the middle of the screen
// 1. calculate center
int centerX = WIDTH/2;
int centerY = HEIGHT/2;
// 2. Draw the center of the big X
putChar(centerX,centerY,'x');
// 3. Draw the topleft->bottomright line
putChar(centerX-2,centerY-2,'x');
putChar(centerX-1,centerY-1,'x');
putChar(centerX+1,centerY+1,'x');
putChar(centerX+2,centerY+2,'x');
// 4. Draw the topright->bottomleft line
putChar(centerX-2,centerY+2,'x');
putChar(centerX-1,centerY+1,'x');
putChar(centerX+1,centerY-1,'x');
putChar(centerX+2,centerY-2,'x');
// 5. Draw the buffer to the screen
drawBuffer();
int asdf;
cin>>asdf;
return 0;
}
void drawBuffer()
{
cout<<screenBuffer;
}
void clearScreen()
{
for (int charIndex = 0; charIndex<WIDTH*HEIGHT;charIndex++)
{
screenBuffer[charIndex] =' ';
}
drawBuffer();
}
void putChar(int x, int y, char c)
{
screenBuffer[y*WIDTH+x] =c;
}





Előző:
Ez C++, C kell a kérdezőnek.
Amúgy printf -el ki lehet rakni.





Tudom, hogy C++, de a cin-t cout-ot lecseréli printf-re, oszt' cső :)
Csak Visual Studio van a gépemen, abban meg C++ van, másrészt meg főiskolás korom óta nem írtam/láttam C kódot, már egy printf-re se emléxek fejből, hogy kell használni :)





*cin-t cout-ot lecseréli printf-re
+és scanf-re, ez kimaradt :D










Kapcsolódó kérdések:
Minden jog fenntartva © 2025, www.gyakorikerdesek.hu
GYIK | Szabályzat | Jogi nyilatkozat | Adatvédelem | Cookie beállítások | WebMinute Kft. | Facebook | Kapcsolat: info(kukac)gyakorikerdesek.hu
Ha kifogással szeretne élni valamely tartalommal kapcsolatban, kérjük jelezze e-mailes elérhetőségünkön!