An overview of what my program does
I'm given a main.cpp file with some function prototypes that I have to define in a separate .cpp to manipulate an image file ( basically a 15 x 15 matrix of 1's and 0's)
The result of your current code

I dont know yet since i've been stuck for the past 2 days with these error :
1>c:\documents and settings\tenn\my documents\visual studio 2008\projects\test\project01.cpp(16) : error C2065: 'MAX_COLS' : undeclared identifier

can any one see why i keep getting that undeclared error?...in my project01.cpp file when you drag the mouse over the MAX_COLS it is showing that it is defined as 15 .. so why the error?

this is what my main.cpp looks like

#include <iostream>			// Header file for cout and endl
#include <iomanip>			// Header file for I/O manipulators
#include <fstream>			// Header file for file io
#include <string>			// Header file for c_str()

using namespace std;			// Global using directive

const	int	MAX_ROWS = 15;		// Maximum number of rows in image
const	int	MAX_COLS = 15;		// Maximum number of cols in image

// Function Prototypes 
// You will need to implement each of the functions below in a separate file named project01.cpp
void	OpenInputFile(string filename, ifstream& inFile);
void	ClearImage(int image[][MAX_COLS]);

int main(int argc, char* argv[])
{
    char		cmd;			// Command input from command file
	int			index;			// Row or column index input from command file
	int			shift;			// Amount of shift input from command file
    int	        image[MAX_ROWS][MAX_COLS];	// Current image stored as a two-dimensional array
	ifstream	imagefile;		// Image file input stream
	ifstream	commandfile;	// Command file input stream
    
    ClearImage(image);			// Initialize image to all 0's

// Verify proper usage -- executable name followed by imagefile and commandfile names
	// on the command line
	if (argc != 3)
	{
	  	cout << "Error: usage  project01 <imagefile> <commandfile>" << endl;
		return 0;
	}
	
	PrintDashes();
	
	// Process command line arguments
	// First argument will be name of image file
	string imagefilename(argv[1]);
	cout << "imagefile = " << imagefilename << endl;
	OpenInputFile(imagefilename, imagefile);   // Invoke OpenInputFile() to open image file
	
	if (!imagefile)
	{
		cout << "-- Error: unable to open image file.  Terminating now. --" << endl;
		PrintDashes();
		return 0;
	}
	else
		cout << "-- Image File Opened Successfully --" << endl;
	PrintDashes();
}  // End of main()

//*************************************************************************************
//*************************************************************************************
//*************************************************************************************

// Note: The include statement below will add the functions you have written in 
//       project01.cpp to this program prior to compilation.  Remember, Linux is 
//       case sensitive so be sure to match the name of your file to the filename below.

#include "project01.cpp"

my project01.cpp file looks like this

#include <iostream>
#include <iomanip>   // for format manipulation 
#include <fstream>   // needed for file I/O
#include <string>
using namespace std;

	//const int	MAX_ROWS;		// Maximum number of rows in image
	//const int MAX_COLS;		// Maximum number of cols in image
void	OpenInputFile(string filename, ifstream& inFile);
void	ClearImage(int image[][MAX_COLS]);

void OpenInputFile(string filename, ifstream& inFile) {
// This functions opens the input file assuming that the file's name is already stored
// in the string parameter, and it provides the input file stream variable to the
// calling function -- all error handling will be done in main()


string line;

//ifstream inFile;
  inFile.open(filename.c_str());


if (inFile.is_open())
  {
    while (! inFile.eof() )
    {
      getline (inFile,line);
      cout << line << endl;
	  //return
   }
    inFile.close();
  }
  //else cout << "Unable to open file"; 


}


void	ClearImage( int image[][MAX_COLS]){
// This function clears an image by placing a zero in every array element
int k,g;

	for(k=0 ; k<MAX_COLS ; k++) {
        for(g=0 ; g<MAX_COLS ; g++) {
                image[k][g] = 0;
        }
    }


}

well if your complier is compiling project01.cpp be for your main.cpp file then it doesn't know what MAX_COLS is yet. try moving the declaration into the project01.cpp file and see what happens

I don't see a PrintDashes () function anywhere. If you add one, then type "g++ main.cpp" in Linux, it compiles for me. Is there a makefile for this? Maybe it's trying to compile project01.cpp into object code and then link, in which case project01.cpp won't know anything about MAX_COLS. But as is, if you add that PrintDashes () function, then do "g++ main.cpp", it compiled for me.

I don't see a PrintDashes () function anywhere. If you add one, then type "g++ main.cpp" in Linux, it compiles for me. Is there a makefile for this? Maybe it's trying to compile project01.cpp into object code and then link, in which case project01.cpp won't know anything about MAX_COLS. But as is, if you add that PrintDashes () function, then do "g++ main.cpp", it compiled for me.

I'm sorry ..Yes there's a PrintDashes() function in the main.cpp file at the very bottom below the # include " project01.cpp" line

and I haven't made a makefile for it as yet since i'm working at home on windows using visual C++ express 2008 so I haven't tested it on linux yet

I'm sorry ..Yes there's a PrintDashes() function in the main.cpp file at the very bottom below the # include " project01.cpp" line

and I haven't made a makefile for it as yet since i'm working at home on windows using visual C++ express 2008 so I haven't tested it on linux yet

I'm not all that familiar with Visual Studio and how it handles everything, but since I tried it out on Cygwin/Linux (after adding a blank PrintDashes) without using a makefile, just using the "g++ main.cpp" command and it compiled, I'm guessing that there is a default makefile that you haven't overridden and that is doing something other than just "g++ main.cpp -o main.exe" (I don't know if Visual Studio uses g++).

This article has been dead for over six months. Start a new discussion instead.