#include <ncurses.h>
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
int main(int argc, char *argv[]){
int x,y,ch;
if(argc != 2){
fprintf(stderr,"there is no value to be show\n");
exit(1);
}
getmaxyx(stdscr,y,x);
initscr();
start_color();
init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK);
init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
init_pair(COLOR_WHITE,COLOR_WHITE, COLOR_BLACK);
keypad(stdscr,TRUE);
crmode();
noecho();
while(ch != 'q'){
mvprintw(y/2, x/2, "%s", argv[1]);
refresh();
ch = getch();
if(ch == 'u'){
attron(COLOR_PAIR(COLOR_GREEN));
mvprintw(y/2, x/2, "%s", strupr(argv[1]));
}
else if(ch == 'l'){
attron(COLOR_PAIR(COLOR_RED));
mvprintw(y/2, x/2, "%s", argv[1]);
}
else if(ch == 'o'){
attron(COLOR_PAIR(COLOR_WHITE));
mvprintw(y/2, x/2, "%s", argv[1]);
}
else{
continue;
}
}
endwin();
return 0;
}
So from this code I want to display string argv[1]
at the center of the terminal. When the user press u
I want to make it uppercase when the user press l
I want to make it into the lowercase. At my code when I want to make the word into the uppercase I want to use strupr
to make it into uppercase but cannot compile this code properly.
It said implicit declaration for the strupr
function.
And I think for putting into the center of the terminal I already make the proper program by using mvprintw(y/2,x/2)
but despite of the word displayed at the center it displayed at the top left of the terminal.
Is there somebody know where my mistake at?