Im writing a code to draw a square onto a screen but its not working for some reason. Its supposed to draw a square to the screen where the square is '#' but the non square area is '0'. When I run the program though it gives me a full screen of '0' but a single '^' in the top left of the terminal. Ive tried listing the values of the square but it says those are zero so I tried changing the way of initalizing the square but it still ended up with zeroes for all the values. I am currently looking into pointers and references to see if those could help but im not completely sure.
#include <unistd.h>
#include <ncurses.h>
int height, width;
class Square {
public:
float x;
float y;
int w;
int h;
char c;
};
Square ball;
void initSquare(Square square, float x, float y, int w, int h, char c);
void Render();
int main(void) {
initscr();
getmaxyx(stdscr, height, width);
initSquare(ball, width/2, height/2, 4, 4, '#');
while(true) {
Render();
usleep(35000);
refresh();
}
return 0;
}
void initSquare(Square square, float x, float y, int w, int h, char c) {
square.x = x;
square.y = y;
square.w = w;
square.h = h;
square.c = c;
}
void Render() {
for(int i = 0; i < height; ++ i) {
for (int j = 0; j < width; ++ j) {
if(j >= ball.x && j <= ball.x+ball.w && i >= ball.y && i <= ball.y + ball.h) {
mvaddch(i, j, ball.c);
} else {
mvaddch(i, j, '0');
}
}
}
}