Maybe the problem isn't with this switch...
I've been playing with this thing for the past 9 hours so I'm going to go ahead and post a very simplified version of main() and 2 other necessary called functions just so you can get an idea of what's going on. I hope that it will compile...I'm picking pieces from all over the place. But if you can get this to work then the entire thing will work.
If you notice anything that just doesn't seem right, be sure to let me know.
Code:
#include <fstream.h>
#include <string.h>
//constants
const int MAXWORDLENGTH = 15;
const int PUZZLEROWS = 15;
const int PUZZLECOLS = 15;
//function prototypes
bool FindWordEW(ofstream&,
char[][PUZZLECOLS],
char[MAXWORDLENGTH + 1]);
void InitializePuzzle(char[][PUZZLECOLS] );
int main()
{
char puzzle[PUZZLEROWS][PUZZLECOLS];
char currentWord[MAXWORDLENGTH];
bool managePassage;
ifstream fileIn;
ofstream fileOut;
fileIn.open("words.dat");
fileOut.open("proj4.out");
fileIn.get(currentWord, MAXWORDLENGTH);
managePassage = FindWordEW(fileOut, puzzle, currentWord);
while(fileIn)
{
switch(managePassage)
{
case 0:
break;
default:
managePassage = FindWordWE(fileOut, puzzle, currentWord);
switch(managePassage)
{
case 1:
break;
case 0:
fileOut << "Not found." << endl;
}// end switch
}//end switch
fileIn.ignore(255, '\n');
fileIn.get(currentWord, MAXWORDLENGTH);
cout << currentWord << endl;
cout << managePassage;
}//end while
return 0;
}//end main;
void InitializePuzzle(char puzzle[][PUZZLECOLS])
{
ifstream fileIn;
fileIn.open("puz.dat");
int i = 0;
int x = 0;
//fills a 2-dimensional array with the contents of a file
for (x = 0; x <= PUZZLECOLS; x++)
{
for (i = 0; i <= PUZZLEROWS; i++)
{
fileIn.get(puzzle[x][i]);
}
}
return;
}
bool FindWordEW(ofstream& fileOut,
char puzzle[][PUZZLECOLS],
char word[MAXWORDLENGTH + 1])
{
int i;
int x;
int a = 0;
int b = 0;
int z = 0;
int y = 0;
int length;
int coord1, coord2;
InitializePuzzle(puzzle);
//find length of the word
length = strlen(word);
//string for comparison
char temp[MAXWORDLENGTH +1];
for (x = 0; x <= PUZZLEROWS; x++)
{
for (i = 0; i <= PUZZLECOLS; i++)
{
//check to see if the first character of word == puzzle[x][i]
if(word[z] == puzzle[x][i])
{
coord1 = x;
coord2 = i;
a = x; //store value of x for manipulation
b = i; //store value of y for manipulation
y = 0; //reset y
while (y < length)
{
//copies the first length number of letters from puzzle to temp
temp[y] = puzzle[a][b];
b--;
y++;
}
while (y < MAXWORDLENGTH +1)
{
//fill the garbage arrays of temp with garbage arrays of word so they are equal
temp[y] = word[y];
y++;
}
if (strcmp(temp,word)==0)
{
fileOut << "The word " << word << " is found starting at (" << coord1 << ",";
fileOut << coord2 << ") moving West." << endl << endl;
return true;
}
}
}
}
return false;
}