Pregunta

Oye, entonces estoy tratando de obtener addstr () en PDCurses a funcionar (maldiciones de Windows) con la clase de cadena preferida, así que hice la función la siguiente función String_To_80Char (), que se supone que toma una cadena y devuelve un caracteres largos de 80 caracteres Array (el número de caracteres que se ajustan en una línea en la consola) ya que este es el único parámetro que ADDSTR parece aceptar ...

Sin embargo, al ejecutar el siguiente código, obtengo la "solo una cadena" impresa pero con un carácter aleatorio como un '@' o '4' como 50 espacios después de ...

¿¿CUÁL ES EL PROBLEMA?? ¡Gracias por la ayuda! =)

#include <curses.h>         /* ncurses.h includes stdio.h */  
#include <string> 
#include <vector>
#include <Windows.h>
#include <iostream>
using namespace std;

char* string_to_80char (const string& aString)
{
    int stringSize = aString.size();
    char charArray[90];

    if(stringSize <= 80)
    {
    for(int I = 0; I< stringSize; I++)
        charArray[I] = aString[I];
    for(int I = stringSize; I < sizeof(charArray); I++)
        charArray [I] = ' ';
    return charArray;
    }

    else
    {
    char error[] = {"STRING TOO LONG"};
    return error;
    }
};


int main()
{
    //   A bunch of Curses API set up:
    WINDOW *wnd;

 wnd = initscr(); // curses call to initialize window and curses mode
 cbreak(); // curses call to set no waiting for Enter key
 noecho(); // curses call to set no echoing

 std::string mesg[]= {"Just a string"};     /* message to be appeared on the screen */
 int row,col;               /* to store the number of rows and *
                     * the number of colums of the screen */
 getmaxyx(stdscr,row,col);      /* get the number of rows and columns */
 clear(); // curses call to clear screen, send cursor to position (0,0)

 string test = string_to_80char(mesg[0]);
 char* test2 = string_to_80char(mesg[0]);
 int test3 = test.size();
 int test4 = test.length();
 int test5 = sizeof(test2);
 int test6 = sizeof(test);

 addstr(string_to_80char(mesg[0]));
 refresh();
 getch();


 cout << endl << "Try resizing your window(if possible) and then run this program again";
  system("PAUSE");
 refresh();
  system("PAUSE");

 endwin();
 return 0;
}

No hay solución correcta

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top