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;
}
}
}