-
April 16th, 2009, 10:08 PM
#1
Help with ncurses (int to string)
I'm playing around with ncurses and when I try to print a int variable I get this error:
invalid conversion from ‘int’ to ‘const char*’
initializing argument 4 of ‘int mvwprintw(WINDOW*, int, int, const char*, ...)’
I think it is because I am trying to print a int when its asking for a string but I don't know what to do.
This is my code:
Code:
#include <iostream>
#include <ncurses.h>
WINDOW *create_newwin(int height, int width, int starty, int startx);
void destroy_win(WINDOW *local_win);
int main(int argc, char *argv[])
{ WINDOW *my_win;
int startx, starty, width, height;
int ch;
int strength;
int curlvl = 1;
initscr(); /* Start curses mode */
cbreak();
keypad(stdscr, TRUE);
height = 3;
width = 10;
starty = (LINES - height) / 2; /* Calculating for a center placement */
startx = (COLS - width) / 2;
printw("Press F6 to exit");
refresh();
if (curlvl = 1){
strength = 5;
}
my_win = create_newwin(height, width, starty, startx);
while((ch = getch()) != KEY_F(6))
{ switch(ch)
{ case KEY_LEFT:
destroy_win(my_win);
my_win = create_newwin(height, width, starty,--startx);
wprintw(my_win, "Hey");
wrefresh(my_win);
break;
case KEY_RIGHT:
destroy_win(my_win);
my_win = create_newwin(height, width, starty,++startx);
break;
case KEY_UP:
destroy_win(my_win);
my_win = create_newwin(height, width, --starty,startx);
break;
case KEY_DOWN:
destroy_win(my_win);
my_win = create_newwin(height, width, ++starty,startx);
break;
case KEY_F(5):
destroy_win(my_win);
break;
case KEY_F(7):
my_win = create_newwin(height, width, starty, startx);
mvwprintw(my_win,1,1, strength);
wrefresh(my_win);
break;
}
}
endwin(); /* End curses mode */
return 0;
}
WINDOW *create_newwin(int height, int width, int starty, int startx)
{ WINDOW *local_win;
local_win = newwin(height, width, starty, startx);
box(local_win, 0 , 0);
wrefresh(local_win); /* Show that box */
return local_win;
}
void destroy_win(WINDOW *local_win)
{
wborder(local_win, ' ', ' ', ' ',' ',' ',' ',' ',' ');
wrefresh(local_win);
delwin(local_win);
}
Last edited by toothyXdip; April 18th, 2009 at 04:35 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|