Gerrit Hohl - 2012-03-15

I'm getting more and more frustrated: I wrote a little C program that does the same as my program + Java Curses Library: It draws a window with the same size and on the same position as in my Java program. And it works perfectly. I'm totally confused.
Here is the line how I compiled the program followed by the source code of the program:

gcc test.c -std=c99 -I/usr/include -L/usr/lib -lncurses -o test

include <ncurses.h>

include <stdio.h>

include <locale.h>

void drawBox(int x, int y, int width, int height, short number, long attr) {
attron(COLOR_PAIR(number) | attr);
move(y, x);
addch(ACS_ULCORNER);
for (int posx = 1; posx < width - 1; posx++) {
addch(ACS_HLINE);
}
addch(ACS_URCORNER);
for (int posy = 1; posy < height - 1; posy++) {
move(y + posy, x);
addch(ACS_VLINE);
move(y + posy, x + width - 1);
addch(ACS_VLINE);
}
move(y + height - 1, x);
addch(ACS_LLCORNER);
for (int posx = 1; posx < width - 1; posx++) {
addch(ACS_HLINE);
}
addch(ACS_LRCORNER);
attroff(COLOR_PAIR(number) | attr);
}

void clearBox(int x, int y, int width, int height, short number, long attr) {
attron(COLOR_PAIR(number) | attr);
for (int posy = 0; posy < height; posy++) {
move(y + posy, x);
for (int posx = 0; posx < width; posx++) {
addch(' ');
}
}
attroff(COLOR_PAIR(number) | attr);
}

void drawString(char str, int x, int y, short number, long attr) {
char
ch;

attron(COLOR_PAIR(number) | attr);
move(y, x);
ch = str;
while (*ch != '\0') {
    addch(*ch);
ch++;
}
attroff(COLOR_PAIR(number) | attr);

}

int main(int argc, char argv[]) {
int x, y, width, height;
char
title = "Welcome\0";
/
* This lines doesn't do a thing if you use Ubuntu Linux.
* But if you replace "UTF-8" with "" you will get some problems.
/

setlocale(LC_ALL, "UTF-8");

initscr();
keypad(stdscr, TRUE);
cbreak();
noecho();
start_color();
init_pair(1, COLOR_BLUE, COLOR_BLUE);
init_pair(2, COLOR_BLACK, COLOR_WHITE);
init_pair(3, COLOR_BLACK, COLOR_BLACK);
init_pair(4, COLOR_RED, COLOR_WHITE);

// --- Screen ---
clearBox(0, 0, COLS, LINES, 1, A_NORMAL);
// --- Window ---
x = 2;
y = 2;
width = COLS - 4;
height = LINES - 4;
drawBox(x, y, width, height, 2, A_NORMAL);
clearBox(x + 1, y + 1, width - 2, height - 2, 2, A_NORMAL);
clearBox(x + width, y + 1, 1, height, 3, A_NORMAL);
clearBox(x + 1, y + height, width, 1, 3, A_NORMAL);
drawString(title, x + ((width - 7) / 2), y, 4, A_NORMAL);

move(0, 0);
refresh();
getch();
endwin();

return 0;

};