Thread: Code Understanding!

  1. #1
    Jill n Jall
    Guest

    Code Understanding!

    can ne1 tell me line by line what this code is doing?
    I have to implement it and still I am confused about its functionality.Basically its reading frem a file containig this.


    File contents::

    Code:
    Function: S(q0, a) = q1, S(q0, b) = q3, S(q1, a) = q2, S(q2, b) = q1, S(q3, a) = q2, S(q2, b) = q1, S(q2, b) = q4, S(q1, b) = q4, S(q3, b) = q4, S(q2, a) = q3, S(q4, a) = q4, S(q4, b) = q4, S(q3, a) = q2.
    
    
    
    
    code:::::
    
    	strcpy(temp2,"Function");
    		if (strcmp(temp,temp2)==0)
    		{
    			transitions= new int*[numStates];
    			for(i=0;i<numStates;i++)
    			{		
    				transitions[i]=new int[numAlphabets];
    			}
    			
    			// intializing the transition table with values.. -1 shows trap state
    			
    			for (i=0;i<numStates;i++)
    			{
    				for (j=0;j<numAlphabets;j++)
    				{
    					transitions[i][j]=-1;
    				}
    			}
    
    			dfa1File.getline(temp,500,'.\n');																
    			int i=0,x=0,y=0,z=0;
    			char* token;
    			int buffer[200];
    			token = strtok( temp, ":,\n.");
    			while( token != NULL )
    			{	
    				x=token[4]-48;
    				token = strtok( NULL, ":,\n.");			
    				y=token[1]-97;
    				z=token[7]-48;				
    				transitions[x][y]=z;
    				token = strtok( NULL, ":,\n.");			
    				i++;
    			}	
    		}

  2. #2
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    I am posting this because you did not use code tags on this thread. In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happier about helping you

    For example:

    Without code tags:

    for(int i=0;i<5;i++)
    {
    cout << "No code tags are bad";
    }

    With Code Tags:
    Code:
    for(int i=0;i<5;i++)
    {
         cout << "This code is easy to read";
    }
    This is of course a basic example...more complicated code is even easier to read with code tags than without.

    I've added code tags for you this time. They can be added by putting [code] at the beginning of your code and [/code] at the end. More information on code tags may be found on the code tag post at the top of every forum. I also suggest you take a look at the board guildlines if you have not done so already.

    This is a common first post mistake, just remember to use [code] tags in the future and you'll get much more help.

    If this is your first time posting here the welcome, and if there's anything I can do or any questions I can answer about these forums, or anything else, please feel free and welcome to PM me.


    Good Luck with your program,

    Kermi3
    Lead Moderator
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 30
    Last Post: 06-19-2006, 12:35 AM
  2. Replies: 1
    Last Post: 03-21-2006, 07:52 AM
  3. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM