clinuxwindowsncursespdcurses

pdcurses on windows - printw() doesn't print long strings (C) - ncurses works fine on linux - possible bug or is my implementation wrong?


The following is my code demonstrating that long strings fail to print with pdcurses.

#include <curses.h>
#include <string.h>

#define SIZE 256

void get_file_data(char *filename, char *file_data)
{
    // CREATES POINTER TO FILE
    FILE *file;

    // LINE BUFF OF FILE
    char buff[SIZE];
    // OPENS GRAPHICS FILE
    file = fopen(filename, "a+");

    // LOOPS UNTIL EVERY LINE HAS BEEN PRINTED
    while(fgets(buff, SIZE, (FILE*)file))
    {
        // PRINTS EACH LINE
        strcat(file_data, buff);
    }
    strcat(file_data, "\n");

    // CLOSES FILE
    fclose(file);
}

int main()
{
    initscr();

    char input[SIZE];
    char str[12800];

    get_file_data("graphic.txt", str);

    printw("%s", str);

    getstr(input);

    endwin();

    return 0;
}

This is the contents of graphic.txt


   -------------------------------------------------------
   |                                                     |
   |                                                     |
   |                                                     |
   |                                                     |
   |                                                     |
   |                                                     |
   |                                                     |
   |                                                     |
   |                                                     |
   |                                                     |
   -------------------------------------------------------

   Hello there!

and this is what my program outputs


   -------------------------------------------------------
   |                                                     |
   |                                                     |
   |                                                     |
   |                                                     |
   |                                                     |
   |                                                     |
   |                                                     |
   |                                   ^]"b

Is there a problem with my code or is this a problem with pdcurses? As mentioned in the title, ncurses works fine on linux, but I'm trying to compile on windows with pdcurses.


Solution

  • The internal buffer for printw() in PDCurses is only 513 characters -- enough for a little over six 80-column lines. Longer strings are truncated. This is something I'll have to think about reorganizing.

    Meanwhile, you could work around it on your end by simply printing each line as you go, since you're already reading them line-by-line --

    while(fgets(buff, SIZE, (FILE*)file))
    {
        // PRINTS EACH LINE
        printw("%s\n", buff);
    }