This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Im trying to write a program using ncurses. the function mvprintw takes (int, int, <printf arguments>);
I am trying to make a function that can render characters or strings to the screen. with the code i have provided, im missing something in my display message function. can anybody help me out or provide some insight?
#include <ncurses.h>
#include "render.h"
int main() {
//initialize the screen
initscr();
cbreak();
noecho();
nonl();
intrflush(stdscr, FALSE);
keypad(stdscr, TRUE);
//write on the screen
int x = 99;
displayMessage("hello world %d", x);
mvprintw(11,10, "hello world %d", x);
refresh();
//wait for user input
getchar();
//close the ncurses window
endwin();
return 0;
}
------------------render.cpp------------------
#include <ncurses.h>
#include <stdio.h>
#include <stdarg.h>
int displayMessage(const char *fmt, ...) {
int rv;
va_list argp;
va_start(argp, fmt);
rv = mvprintw(10,10, fmt, argp);
return rv;
}
and here is the output, the first number is different every time i run it.
hello world 1027281632
hello world 99
SOLVED: the problem was the mvprintw() function does not take the printf arguments, however, the va_printf() ncurses function does. so swapping out the display function worked fine.
Subreddit
Post Details
- Posted
- 4 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnprogra...