perfectstranger 0 Newbie Poster

I have a dfa program that gets DFA's properties from a text file and tries given string is accepted or rejected by dfa. I have some problems and can't get rid of this. Can anybody help? Here is my code.

#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
	string states,start,final,alphabet,temp;
	string GMI;//give me input=)
	char* filename;
	int i;
	string functions[10];
	filename=new char[100];
	//GET FILE NAME
	cout<<"Enter Filename(Probably DFA.txt):";
	cin>>filename;
	//OPEN FILE
	ifstream file(filename);
	//CONTROL IF IT'S OPENED
	if(!file.is_open()) {
		cout<<"file is not opened"<<endl;
		exit(0);
	}
	if(file.is_open()) {
		cout<<"file is opened"<<endl;
	}
	//GET LINES TO STRINGS
	getline(file,states);
	cout<<states<<endl;
	getline(file,alphabet);
	cout<<alphabet<<endl;
	cout<<"Functions start"<<endl;
	for(i=0;i<states[0]-48;i++) {
		getline(file,temp);
		functions[i]=temp;
		cout<<functions[i]<<endl;
	}
	cout<<"Functions end"<<endl;
	getline(file,start);
	getline(file,final);
	cout<<final<<endl<<endl;
	//GET AN INPUT
	cin>>GMI;
	string current=start;
	int currentINT=current[0]-48;
	//CONTROL THE INPUT
	for(i=0;i<GMI.length();i++) {
		int temp=GMI[i]-48;
 		cout<<"q"<<currentINT<<" to "<<functions[currentINT][temp]<<endl;
		currentINT=functions[currentINT][temp]-48;
	}
	int a=0;
	//Determine a/r
	for(i=0;i<final.length();i++) {
		if(currentINT==final[i]-48) {
			cout<<"ACCEPT"<<endl;
			a=1;
		}
		
	}
	if(a!=1) {
		cout<<"REJECT"<<endl;
	}


}

Text file is like that;

3 // Q={q0,q1,q2}

0 1 //A={0,1}

0 1 //D((q0,0))=q0; D((q0,1))=q1

1 2 //D((q1,0))=q1; D((q1,1))=q1

0 0 //D((q2,0))=q0; D((q2,1))=q0

1 // S= q1

0 1 // F={q0,q1}

The program will take two inputs:

-- The filename describing the DFA

-- The input string

The program will then output the states the machine goes through
while processing the input string on the input string. It will also
state whether the string is accepted or rejected by the given machine.

More details @ http://homes.ieu.edu.tr/~bhnich/CS208-Spring07-08/dfa-prog.txt

Can anybody help me to get rid of this problem? I also need to convert it to NFA system.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.