Coming soon - Get a detailed view of why an account is flagged as spam!
view details

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.

1
I'm struggling to understand passing arguments
Post Body

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.

Author
Account Strength
100%
Account Age
11 years
Verified Email
Yes
Verified Flair
Yes
Total Karma
6,099
Link Karma
661
Comment Karma
5,432
Profile updated: 6 days ago
Posts updated: 10 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
4 years ago