i've been at this for an hour, feeling stupid by now, getting sick of these segmentation faults..

//   board.cpp 
 
#include <iostream> 
using namespace::std; 
 
 
const int NUM_ROWS = 10,   // Board dimensions 
          NUM_COLS = 20; 
 
// Function prototypes 
 
void fillRectangle ( char board[NUM_ROWS] [NUM_COLS] , 
                     int row, int col, 
                     int width, int height, char fillChar ); 
 
void displayBoard ( const char board[NUM_ROWS] [NUM_COLS] ); 
 
//-------------------------------------------------------------------- 
 
int main () 
{ 
    char board[NUM_ROWS][NUM_COLS];   // Message board 
 
    // Initialize the message board to all periods. 
    fillRectangle(board,0,0,NUM_COLS,NUM_ROWS,'.'); 
 
    //  Load and display a message. 
    fillRectangle(board,2,2,6,2,'C'); 
    fillRectangle(board,4,2,3,4,'C'); 
    fillRectangle(board,6,5,3,2,'C'); 
    fillRectangle(board,4,10,3,1,'#'); 
    fillRectangle(board,3,16,1,3,'#'); 
    fillRectangle(board,3,11,1,3,'#'); 
    fillRectangle(board,4,15,3,1,'#'); 
    cout << endl; 
    displayBoard(board); 
 
    return 0; 
} 
 
//-------------------------------------------------------------------- 
// Insert your function implementations here. 
//-------------------------------------------------------------------- 
 
void fillRectangle ( char board[NUM_ROWS][NUM_COLS], 
                     int row, int col, 
                     int width, int height, char fillChar ) 
 
// Fills in the specified rectangle on the message board with the 
// character fillChar. 
 
 
{ 
     
    for(int i = row; i < width + row; i++) 
        
        for(int j = col; j < height + col; j++) 
 
            board[i][j] = fillChar; 
 
 
} 
 
//-------------------------------------------------------------------- 
 
void displayBoard ( const char board[NUM_ROWS][NUM_COLS]) 
 
// Displays the message board. 
 
{ 
     
    for(int i = 0; i < NUM_ROWS; i++)
        for(int j = 0; j < NUM_COLS; j++)
            cout << board[i][j]; 
 
 
 
}

/*

....................
....................
..CCCCCC............
..CCCCCC...#....#...
..CCC.....###..###..
..CCC......#....#...
..CCCCCC............
..CCCCCC............
....................
....................

*/

The only problem with ur code is that u are passing parameters to the function fillRectangle ( ... ) in the wrong order ( yes u heard it right WRONG ORDER).

The first call to fillRectangle ( ... ) should not be fillRectangle (board, 0, 0, [B]NUM_COLS, NUM_ROWS[/B], '.'); but it should be

fillRectangle (board, 0, 0, [B]NUM_ROWS, NUM_COLS[/B], '.'); The rest of the code is fine.
Hope u have understood the problem.

An alternative method which can save u from such bugs is to write two functions like void initialiseBoard (const char reqChar) to initialise with the req char and then call the method fillRectangle ( ... ) .

Hope it helped,
Bye.

oh great, the code i'm not writing is fucked. i'm glad this class is over wednesday.

the output i get from my code.

....................
....................
..CC................
..CC.......###..###.
..CCCC....#....#....
..CCCC....#....#....
..CCCCC...#....#....
..CC.CC.............
.....CC.............
....................

//   board.cpp 
 
#include <iostream> 
using namespace::std; 
 
 
const int NUM_ROWS = 10,   // Board dimensions 
          NUM_COLS = 20; 
 
// Function prototypes 
 
void fillRectangle ( char board[NUM_ROWS] [NUM_COLS] , 
                     int row, int col, 
                     int width, int height, char fillChar ); 
 
void displayBoard ( const char board[NUM_ROWS] [NUM_COLS] ); 
 
//-------------------------------------------------------------------- 
 
int main () 
{ 
    char board[NUM_ROWS][NUM_COLS];   // Message board 
 
    // Initialize the message board to all periods. 
    fillRectangle(board,0,0,NUM_ROWS,NUM_COLS, '.'); 
 
    //  Load and display a message. 
    fillRectangle(board,2,2,6,2,'C'); 
    fillRectangle(board,4,2,3,4,'C'); 
    fillRectangle(board,6,5,3,2,'C'); 
    fillRectangle(board,4,10,3,1,'#'); 
    fillRectangle(board,3,16,1,3,'#'); 
    fillRectangle(board,3,11,1,3,'#'); 
    fillRectangle(board,4,15,3,1,'#'); 
    cout << endl; 
    displayBoard(board); 
 
    return 0; 
} 
 
//-------------------------------------------------------------------- 
// Insert your function implementations here. 
//-------------------------------------------------------------------- 
 
void fillRectangle ( char board[NUM_ROWS][NUM_COLS], 
                     int row, int col, 
                     int width, int height, char fillChar ) 
 
// Fills in the specified rectangle on the message board with the 
// character fillChar. 
 
 
{ 
     
    for(int i = row; i < width + row; i++) 
        
        for(int j = col; j < height + col; j++) 
 
            board[i][j] = fillChar; 
 
 
} 
 
//-------------------------------------------------------------------- 
 
void displayBoard ( const char board[NUM_ROWS][NUM_COLS]) 
 
// Displays the message board. 
 
{ 
     
    for(int i = 0; i < NUM_ROWS; i++)
        for(int j = 0; j < NUM_COLS; j++) {
            cout << board[i][j];
            if(j == NUM_COLS - 1)
                cout << endl;
        }


}

oh great, the code i'm not writing is fucked. i'm glad this class is over wednesday.

What the hell is this supposed to mean !!!

Explicit content is not allowed on the site even if it reflects ur feelings.
And with this kind of replies i dont think you would get any help in the future so it would be better if u stop saying such things and apologise.

it means the code from the manual is supposedly wrong. nothing against you.. sorry.

the function calls were part of the handout template. so i just *assume* they're written correctly :-(

Ok apology accepted, but wat do u now expect, wat is the prob with the code now ?

it's supposed to look like this:

.................... 
.................... 
..CCCCCC............ 
..CCCCCC...#....#... 
..CCC.....###..###.. 
..CCC......#....#... 
..CCCCCC............ 
..CCCCCC............ 
.................... 
....................

NEvermind, it's working now. you're right i had to change more of the professor's code to make it work. argh thanks

Just out of curiosity, who wrote this code?

int main () 
{ 
    char board[NUM_ROWS][NUM_COLS];   // Message board 
 
    // Initialize the message board to all periods. 
    fillRectangle(board,0,0,NUM_COLS,NUM_ROWS,'.');

it is part of the Small C++ how to program online section, prentice hall authors, taken directly from the lab manual.

Just out of curiosity, who wrote this code?

int main () 
{ 
    char board[NUM_ROWS][NUM_COLS];   // Message board 
 
    // Initialize the message board to all periods. 
    fillRectangle(board,0,0,NUM_COLS,NUM_ROWS,'.');

He says its given in the manual, or maybe written by his professor.
Why, do u like it that much ;)]

Maybe u thinkin y to pass so many parameters if u eventually want to initialise the whole board.

Just write, void initialiseBoard (char reqChar);

Why, do u like it that much ;)

Because in these forums you get people who say everything is the fault of everybody else but themselves.

Yes sad but true but i pointed out this thing to him saying that it was his typing mistake and not the textbook's. So he may hopefully not blame the author in the future.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.