ok, so ive rattled my brain for quite some time now and im tired, i need help on my program because as of now, im down to 2 debugging errors "YAY!"...
here is what the debugger says...
"
Line 7: error: too few arguments to function `void nextArray(bool (*)[20])'
Line 25: error: at this point in file
Line 8: error: too few arguments to function `void printArray(bool (*)[20])'
Line 26: error: at this point in file
"

and here is my code...

#include <iostream>
#include <fstream>
using namespace std;

const int SIZE = 20;
void lifegrid(int , int , bool [] [SIZE]);
void nextArray(bool [] [SIZE]);
void printArray(bool [] [SIZE]);


int main () 
{
    bool life[SIZE][SIZE];
    
	string keyboardinput;
	

	
	do {
		keyboardinput = "";
		cout << "Enter \"n\" for next cycle, anything else to quit... ";
		cin >> keyboardinput;
		cout << endl;
		
		nextArray();
		printArray();
		cout << endl;//total alive in row 10
        int row=10;
        int rowtotal=0;
        for (int col = 0; col < SIZE; col++)
        {
            if(life[row][col])
            rowtotal=rowtotal+1;
        }
        cout<<"total alive in row 10 is "<<rowtotal<<endl;
        //total alive in col 10
        int col=10;
        int coltotal=0;
        for (int row = 0; row < SIZE; row++)
        {
            if(life[row][col])
            coltotal=coltotal+1;
        }
        cout<<"total alive in column 10 is "<<coltotal<<endl;
        //total alive in grid  
        int totalalive=0;
         for (int row = 0; row < SIZE; row++)
    {
        for (int col = 0; col < SIZE; col++)
        {
           if( life[row][col])
           totalalive++;
        }
    }   
    cout<<"total alive cells is "<<totalalive<<endl; 


		
	} while (keyboardinput == "n");
	
	cout << "Goodbye." << endl;
	system("PAUSE");
	return 0;
}




void lifegrid(int a, int b, bool life[] [SIZE]) {
	int row, col;
    
    row = a;
	col = b;
	
	
    ifstream inData;
    string fileName;
    
    cout<<"Please enter filename"<<endl;
    cin>>fileName;
    inData.open(fileName.c_str());
    
   inData>>row>>col;
   while(inData)
   {
     life[row][col]=true;
      inData>>row>>col;
   }       
} 
	



void nextArray(bool life[] [SIZE]) {
	
	int row, col;
	int numAround = 0;
	bool templife [row][col];
	
	for (int i = 0; i < row; i++)
	{
		for (int j = 0; j < col ; j++)
		{
			if ( (i+1) < row && life[i + 1][j] == true )
			{
				numAround++;
			}
			if ( (i-1) >= 0 && life[i - 1][j] == true )
			{
				numAround++;
			}
			if ( (j+1) < col && life[i][j+1] == true )
			{
				numAround++;
			}
			if ( (j-1) >= 0 && life[i][j-1] == true )
			{
				numAround++;
			}
			if ( (i+1) < row && (j+1) < col && life[i+1][j+1] == true )
			{
				numAround++;
			}
			if ( (i+1) < row && (j-1) >= 0 && life[i+1][j-1] == true )
			{
				numAround++;
			}
			if ( (i-1) >= 0 && (j+1) < col && life[i-1][j+1] == true )
			{
				numAround++;
			}
			if ( (i-1) >= 0 && (j-1) >= 0 && life[i-1][j-1] == true )
			{
				numAround++;
			}
			
			if (numAround < 2 || numAround > 3)
			{
				templife[i][j] = false;
			}
			else if (numAround == 2)
			{
				templife[i][j] = life[i][j];
			}
			else if (numAround == 3)
			{
				templife[i][j] = true;
			}
			
			numAround = 0;
			
		}
	}
	
	for (int i = 0 ; i < row ; i++ )
	{
		for (int j = 0 ; j < col ; j++ )
		{
			life[i][j] = templife[i][j];
		}
	}
}


void printArray(bool life[] [SIZE]) {
     int row, col;
	for (int i = 0; i < row ; i++ )
	{
		for (int j = 0 ; j < col ; j++ )
		{
			if ( life[i][j] == true )
			{
				cout << "x";
			}
			else
			{
				cout << " ";
			}
			
			if ( (j + 1) >= col )
			{
				cout << endl;
			}
		}
	}
}

i know its kind of crappy and a bit hacked together, but thats how i role... my hair is a mess too... help would be much appreciated, as the program is due in 21 hours... i am eager to learn anything you guys can throw at me to fix what i need to fix to get this program off my back.
thanks a bunch, hope some 1 can help me ^_^

Dani AI

Generated

Brief diagnosis and next steps (grounded in 's pointer): two distinct problems were in play. The compile errors came from calling functions without the required arguments; that is fixed by passing the grid. The subsequent runtime crash is classic undefined behavior: helper functions declare local row/col variables but never set them, then use those uninitialized values when declaring or indexing arrays (and the main grid was never zero-initialized). That combination produces invalid memory accesses and a crash.

Concrete fixes to apply:

  • Make the grid dimension explicit in the functions (use the global SIZE or pass dimensions). Do not declare uninitialized row/col inside nextArray or printArray.
  • Initialize the main grid when declared (zero-initialize so all cells start dead).
  • Use a well-sized temporary grid for the next generation (e.g., a fixed-size array or a std::array/std::vector), set it entirely before copying back, and declare the neighbor count inside the inner loop so it doesn’t carry over.
  • Validate file input coordinates before setting a cell alive and call the file-loading function once before the main loop.

A safe pattern (keeps bounds-checking simple and avoids VLA/UB) is shown below:

#include <array>
const int SIZE = 20;
using Grid = std::array<std::array<bool, SIZE>, SIZE>;

void nextArray(Grid &life) {
    Grid temp{}; // all false
    for (int i = 0; i < SIZE; ++i) {
        for (int j = 0; j < SIZE; ++j) {
            int neighbors = 0;
            for (int di = -1; di <= 1; ++di) {
                for (int dj = -1; dj <= 1; ++dj) {
                    if (di == 0 && dj == 0) continue;
                    int ni = i + di, nj = j + dj;
                    if (ni >= 0 && ni < SIZE && nj >= 0 && nj < SIZE)
                        neighbors += life[ni][nj];
                }
            }
            temp[i][j] = (neighbors == 3) || (neighbors == 2 && life[i][j]);
        }
    }
    life = temp;
}

Extra tips: compile with warnings enabled (e.g., -Wall -Wextra), run under a debugger or Valgrind to catch invalid reads/writes, and keep function interfaces simple (pass the grid by reference or use a type alias). These changes resolve the crash sources seen after ’s compile-fix and make the simulation robust.

Recommended Answers

All 2 Replies

> nextArray();
You said it needed a parameter, but you didn't pass any!

Try
nextArray(life);

oh haha, thanks, well, now it compiles... but it crashes and i get an error report when i try to do anything... so ive scraped that code and redone my program...

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.