I keep getting a segmentation fault when I run it. Program will not get past the prinf line. Here is my code Code: #include <fstream> #include <iostream> #include <cstdlib> using namespace std; int main(int argc,char **argv) { int i,j,xres,yres,max,**image; ofstream fp; // xres, yres, maxintensity, and image[][] must already be defined cin >> xres; cin >> yres; fp.open(argv[1]); cout << "P2" << endl; cout << xres << " " << yres << endl; cout << "255" << endl; // Almost always equals 255 for (i=0;i<xres;i++) for (j=0;j<yres;j++) printf("%4d", image[i][j]); return 0; }
So where is image initialized? Why are you mixing C++ io (cin/cout) and C stdio (printf) you should pick one type or the other. Jim
No it's not. See those two asterisks? They change the meaning significantly. Also look at the comment; that should give you a clue. The reason for the segfault is basically that you've ignored the comment and are trying to use an uninitialised 2D array.