Program just gives a black screen

I am having trouble getting the program to do anything. I know it will not run here because of ncurses, but it does compile. when I run the program, a black screen shows and nothing happens. I am pretty confident on the code( I tested it all in a main function). The problem I think is with my function calls (maybe the Fill() function) in the scatter function. or maybe the problem is also within my constructors. If anyone can look it over and see if I am calling correctly or give any pointers. the header files do not need any changes, just the .cpp files.

this program just writes a char randomly to the screen until full and repeats.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193


// cmatrix.h

#ifndef CMATRIX_H
#define CMATRIX_H

#include  <iostream>
#include  <fstream>

class   CMatrix
{
public:
    CMatrix(int numRows, int numCols);

   void  Fill(char  dispChar, int msecs);

private:
    int    m_numRows;
    int    m_numCols;
};

#endif





//  cmatric.cpp
#include   <cstdlib>
#include   <ctime>
#include   <fstream>
#include   <ncurses.h>
#include   <unistd.h>
using namespace std;
#include   "cmatrix.h"  

// constructor - it initializes the data members so the screen size is know to 
// the matrix ADT

CMatrix::CMatrix(int numRows, int numCols)
{
    m_numRows = numRows;
    m_numCols = numCols;
}




// this function fills the screen with a char at random locations until the 
// screen is full. then returns to caller

void   CMatrix::Fill(char dispChar, int msecs)
{
   int    totalArea = m_numRows*m_numCols;
   int    counter=0;
   int    rows, cols, y, x;
   bool   matrix[m_numRows][m_numCols];

//  code is- set a 2D bool matrix, a do loop to write a char to fill
//  screen then stop loop 




//  cscreen.h
#ifndef CSCREEN_H
#define CSCREEN_H

#include  <iostream>
#include  <fstream>

const char DEFAULT_DISPCHAR = '$';
const int  DEFAULT_SLEEP = 2000;
const int  LAST_COLOR_PAIR_INDEX = 7;

class  CScreen
{
public:
    CScreen(const char fname[]);

    void   InitCurses90;
    void   Scatter();

private:
    char    m_dispChar;
    char    m_sleep;
};
#endif

// cscreen.cpp

#include  <cstdlib>
#include  <ctime>
#include  <fstream>
#include  <ncurses.h>
#include  <unistd.h>
using namespace std;
#include   "cscreen.h"  
#include   "cmatrix.h"




// constructor- it uses the parameter to open the configuration  
//file and get the display char and sleep time to initialize the object.
//if file can not be read or open, default values are used.
//a random number generator is seeded and the curse library is initialized
//before returning.  

CScreen::CScreen(const char  fname[])
{
   char      myChar;
   int       myInt, maxRows,maxCols;
   ifstream  file;
 
   file.open(fname);
   if(file.fail())
     {
     m_dispChar = DEFAULT_DISPCHAR;
     m_sleep = DEFAULT_SLEEP;
     }
   else
     {
     file >> myChar >> myInt;
     m_dispChar = myChar;
     m_sleep = myInt;
     }
   file.close();
  
   CScreen::InitCurses();
   srand(time(NULL));                     //  not sure if this is correct way
   getmaxyx(stdscr, maxRows, maxCols);    //  to call the functions
   Cmatrix   cmatrix(maxRows, maxCols);
}





//this function initializes the curse library and establishes the color 
//pairs.

void   CScreen::InitCurses()
{
   initscr();
   start_color();
   init_pair(1, COLOR_RED, COLOR_GREEN);
   // repeat six more times with different color pairs
   curs_set(0);
}

// This function has a infinite loop. inside the loop a COLOR_PAIR is 
// set and a local CMatrix object is used to fill the screen. after the 
// after screen is full and does it again until Ctrl+c.

void    CScreen::Scatter()
{
  int   index = 7;
   
  while (index <=7)
      {
      attron(COLOR_PAIR(index));
      CMatrix    mFill(m_dispChar, m_sleep);    // is this the correct way to
      index--;                                  // to call another member
      refresh();                                // function of a different 
      if (index == 0)                           // class.
        {
        index=7;
        }
    sleep(1);
      }
getch();
endwin();
}



//  Main.cpp


// no changes needed here also.


#include   "cscreen.h"

int    main()
{
     CScreen     screen("config.dat");

     screen.Scatter();
     return 0;
}
Last edited on
 
CMatrix(int numRows, int numCos);


Looks like a typo at the beginning.
The problem I think is with my function calls (maybe the Fill() function) in the scatter function

There is no call to Fill in the Scatter function. A CMatrix object is created, then ignored over and over again courtesy of an infinite loop.

You call Scatter correctly on line 191. Likewise, you'll need to call Fill on a CMatrix object.

You do the same thing in the last line of your CScreen constructor (minus the infinite loop.)
Last edited on
Topic archived. No new replies allowed.