Hi all,

I'm writing a program for school and I am having a weird problem. It's a menu driven program which allows the user make choices, do what is involved in the choice, then return to the main menu and make another choice. Each choice coincides with opening a certain input file and reading into some global variables.

My problem is when I run any choice from scratch, i.e. it's the first choice, the program runs fine, when I come back to the main menu and make another selection, the input file does not get read correctly. I have attached the code that is relevant to my problem. If anyone can help me I would really appreciate it. If you need more explanation or more info I'd be happy to put it up.

I've checked to see if the file does not get opened properly and also if there is a read error, but there is neither. When I print out the variables after the second choice is made all the variables remain the same accept that the "alph" array is empty. I can't make heads or tails of it. It just seems that the variables are not being touched the second time around.

In a nutshell, the program should prompt the user for a choice, open the file corresponding to the choice and read in the variables, then perform the checkstr() function. When returning from checkstr() it will break from the switch and then theoretically start over since it's do_while(true). The theoretically is where the problem is.

Thanks in advance.

Code:
#include <windows.h>
#include <conio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

using namespace std;

fstream my_input_file;

int menu_ch,
	start_st,
	no_fin_sts,
	fin_sts[200],
	no_rows,
	no_cols,
	tran_table[200][200],
	cur_st,
	nex_st,
	input_exh,
	inptr,
	alph_len,
	k;

string file_path;

char alph[200],
	 in_str[1000];

void display_menu();
void open_file();
void check_str();
void trace_disp();

int main(void)
{

	//HANDLE hConsole = GetStdHandle ( STD_OUTPUT_HANDLE );

	do
	{
		system("cls");

		display_menu();

		cin >> menu_ch;
		
		switch(menu_ch)
		{
			case 1:
				file_path = "notripcd.txt";
				open_file();
				check_str();
				break;

			case 2:
				file_path = "decdiv25.txt";
				open_file();
				check_str();
				break;

			case 3:
				file_path = "genome.txt";
				open_file();
				check_str();
				break;
	
			case 4:
				cout << "\nPlease enter the path of your file: ";
				cin  >> file_path;
				open_file();
				check_str();
				break;

			case 5:
				exit(0);

			default:
				cout << "\n\tInvalid entry please try again!!\n\n\t";
				system("pause");
		}

	}while(true);

	return 0;

}

void open_file()
{
	my_input_file.open(file_path.c_str(), ios::in);

	if(my_input_file.bad())
	{
		cout << "Error reading file!";
		exit(0);
	}

	my_input_file >> start_st >> no_fin_sts;

	for(int i=0;i<no_fin_sts;i++)
		my_input_file >> fin_sts[i];

	my_input_file >> alph >> no_rows >> no_cols;
	
	for(i=0;i<no_rows;i++)
	{
		for(int j=0;j<no_cols;j++)
			my_input_file >> tran_table[i][j];
	}

	my_input_file.close();

}