Click here to Skip to main content
15,903,388 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,
Please help me out, I can't understand whats the problem in this code.

CODE:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NFAtoDFA
{
    class Program
    {
        public static string[,] ArrOfAllStates = new string[11, 3];
        static string state;
        static string s3;
        public static void Main(string[] args)
        {
            ArrOfAllStates[0, 0] = "1,2,4,7";            //for empty
            ArrOfAllStates[0, 1] = null;              //for a
            ArrOfAllStates[0, 2] = null;              //for b
            //for state 1 of NFA
            ArrOfAllStates[1, 0] = "2,4";            //for empty
            ArrOfAllStates[1, 1] = null;              //for a
            ArrOfAllStates[1, 2] = null;              //for b
            //for state 2 of NFA
            ArrOfAllStates[2, 0] = null;            //for empty
            ArrOfAllStates[2, 1] = "3";              //for a
            ArrOfAllStates[2, 2] = null;              //for b
            //for state 3 of NFA
            ArrOfAllStates[3, 0] = "1,2,4,6,7";            //for empty
            ArrOfAllStates[3, 1] = null;              //for a
            ArrOfAllStates[3, 2] = null;              //for b
            //for state 4 of NFA
            ArrOfAllStates[4, 0] = null;            //for empty
            ArrOfAllStates[4, 1] = null;              //for a
            ArrOfAllStates[4, 2] = "5";              //for b
            //for state 5 of NFA
            ArrOfAllStates[5, 0] = "1,2,4,6,7";            //for empty
            ArrOfAllStates[5, 1] = null;              //for a
            ArrOfAllStates[5, 2] = null;              //for b
            //for state 6 of NFA
            ArrOfAllStates[6, 0] = "1,2,4,7";            //for empty
            ArrOfAllStates[6, 1] = null;              //for a
            ArrOfAllStates[6, 2] = null;              //for b
            //for state 7 of NFA
            ArrOfAllStates[7, 0] = null;            //for empty
            ArrOfAllStates[7, 1] = "8";              //for a
            ArrOfAllStates[7, 2] = null;              //for b
            //for state 8 of NFA
            ArrOfAllStates[8, 0] = null;            //for empty
            ArrOfAllStates[8, 1] = null;              //for a
            ArrOfAllStates[8, 2] = "9,10";              //for b
            //for state 9 of NFA
            ArrOfAllStates[9, 0] = null;            //for empty
            ArrOfAllStates[9, 1] = null;              //for a
            ArrOfAllStates[9, 2] = "10";              //for b
            //for state 10 of NFA
            ArrOfAllStates[10, 0] = null;            //for empty
            ArrOfAllStates[10, 1] = null;              //for a
            ArrOfAllStates[10, 2] = null;              //for b
            ////////////////////////
            Move(E_Closure(0));
        }
        public static string E_Closure(int i)
        {
            Console.Write("Enter state name:");
            state = Console.ReadLine();
            state = ArrOfAllStates[i, 0];
            i++;
            return state;
        }
        public static void Move(string s)
        {
            string[] str = s.Split(',');
            string[] s1=new string[str.Length];
            for(int m=0;m<str.Length;m++)
            s1[m] = ArrOfAllStates[int.Parse(str[m]), 1]+"," + E_Closure(int.Parse(ArrOfAllStates[int.Parse(str[m]), 1]));// exception raised
            
            foreach (string s2 in s1)
                s3 = s2;
            Console.WriteLine("State= {" + s3 + " }");
        }
        
    }
}
Posted
Updated 8-Jun-11 8:53am
v2
Comments
Gonzoox 8-Jun-11 16:24pm    
did Microsoft removed the debug option for the code??? man, I'm happy I got the last version with it

farah javed wrote:
Console.Write("Enter state name:");
state = Console.ReadLine();
state = ArrOfAllStates[i, 0];

This sequence looks illogical to me.
 
Share this answer
 
The problem of the code is that this is not programming at all. Programming is about abstraction and code re-use, but you're repeating almost identical fragments of code many time and think that someone will volunteer to read that. You don't even explain what seems to be a problem to you.

Learn some programming at least on a very elementary level. Look at some good code; it should give you some ideas. Start programming, face some problem you cannot resolve your self, then come back.

—SA
 
Share this answer
 
I have no idea what's wrong with the code (because I didn't bother to look at it), but I will tell you what's wrong with your question. You didn't specify what you were expecting the code to do and what it is actually doing. You also didn't provide any error messages, if any.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900