IITDU Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

DFA code

3 posters

Go down

DFA  code Empty DFA code

Post by BIT0322-Hira Thu Aug 11, 2011 4:56 pm

How can I write a program (in c) that expresses DFA with its transition states? Example:Simulate DFA that accepts substring 01.

BIT0322-Hira
Alpha Release
Alpha Release

Course(s) :
  • BIT

Blood Group : O+
Posts : 24
Points : 33

Back to top Go down

DFA  code Empty Re: DFA code

Post by BIT0208-Shuvo Thu Aug 11, 2011 8:44 pm

Your problem is not clear, would you please be more assertive?
And your topic title is not also meaningful. It's not explaining what you are going to ask or discuss.
BIT0208-Shuvo
BIT0208-Shuvo
Global Moderator-RC

Course(s) :
  • BIT

Blood Group : B+
Posts : 87
Points : 124

Back to top Go down

DFA  code Empty Re: DFA code

Post by BIT0130-Shakkhor Fri Aug 12, 2011 1:51 am

Here's a very simple and naive way of doing this:

Code:
#include <stdio.h>
#include <conio.h>


void state1();
void state2();
void acceptState();
void initialState();


int main()
{
    initialState();
    getch();
}

void initialState()
{
    printf("\nYou've reached initial state.");
    state1();
}

void state1()
{
    printf("\nYou've reached state 1. Enter input:");
    if(getch()=='0') state2();
    else state1();
}

void state2()
{
    printf("\nYou've reached state 2. Enter input:");
    if(getch()=='1') acceptState();
    else state1();
}

void acceptState()
{
    printf("\nYou've reached final state.\nPress any key to exit...");
}

This is a very poor way, and you should probably do something different. For example, you may try a transition table based implementation.
BIT0130-Shakkhor
BIT0130-Shakkhor
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 209
Points : 328

Back to top Go down

DFA  code Empty Re: DFA code

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum