console stops responding

I'm not sure if this is a problem with my code or with my computer...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
int main(){
	ifstream infile;
	ofstream outfile;
	string words[k];						//this is the array that the words from the infile will be stored in
	char thegrid[r][c];						//this is the multideminsional array that will store the actuall word search
	cout<<"welcome to the Word Finder Generator\n\n";
	getfile(infile);						//gets the infile from the user
	populatearray(infile, words);			//uses that file to fill words[]
	infile.close();
	system("CLS");
	fillgrid(thegrid);						//fills thegrid[][] with '.'
	displaygrid(thegrid);					//manages the modules that print thegrid[][]
	placeword(words, thegrid);				//manages the modules that test and place the words where the user specifies
	cout<< "The puzzle is complete.\n";
	system("pause");
	CompletePuzzle(thegrid);				//Fills in all the left over '.' chars in thegrid[][] after the user has placed the words
	displaygrid(thegrid);
	getfile2(outfile);						//gets the file from the user that the puzzle will be stored in
	PutPuzzleAway(thegrid, words, outfile);	//stores thegrid[][] in the file earlier specified
	outfile.close();
	return 0;
}
void getfile2(ofstream& outfile)
{
	//takes ofstream outfile by refrence and opens the
	//file the user wishes to put the puzzle into
	string filename;
	cout<<"\n\nPlease enter the name of the file you would like to put the puzzle in: ";
	cin >> filename;
	outfile.open(filename.c_str());
	return;
	}
void PutPuzzleAway(const char grid[][c], string words[], ofstream& outfile)
{	//the last module to be executed
	// takes thegrid[][] and the ofstream outfile
	//prints grid[][] into the outfile
	int j, k, i; //counters
	for (j=0;j<c;j++){
		for(k=0;k<r;k++)
			outfile<<grid[j][k];
		outfile<<endl;
	}
	for(i=0;i<k;i++)
		outfile<<words[i]<<endl;
}

basically i get through the entirety of the execution i enter the name of the outfile and it tells me the program has stopped responding... This is like no error i have ever gotten while writing in c++ and i am confused as to what could be MCVS 2010 doesnt give me an error or warning message what do you guys think?
for some reason it works without that last for loop in PutPuzzleAway
I'm guessing you are trying to access elements outside of your array.
1
2
for (j=0;j<c;j++){
	for(k=0;k<r;k++)

What happens if you change that to this:
1
2
for (j=0;j<r;j++){
	for(k=0;k<c;k++)
Are you sure that this nested loop is nested in the right order??
1
2
3
4
5
    for (j=0;j<c;j++){
        for(k=0;k<r;k++)
            outfile<<grid[j][k];
        outfile<<endl;
    }


I ask because the grid is defined as
char thegrid[r][c];

not as
char thegrid[c][r];

What are the values of r and c ??
Topic archived. No new replies allowed.