DFA code
3 posters
IITDU Forum :: Academics (BIT) :: Semester 2 :: SE 205
Page 1 of 1
DFA code
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
- Course(s) :
- BIT
Blood Group : O+
Posts : 24
Points : 33
Re: DFA code
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.
And your topic title is not also meaningful. It's not explaining what you are going to ask or discuss.
BIT0208-Shuvo- Global Moderator-RC
- Course(s) :
- BIT
Blood Group : B+
Posts : 87
Points : 124
Re: DFA code
Here's a very simple and naive way of doing this:
This is a very poor way, and you should probably do something different. For example, you may try a transition table based implementation.
- 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- Programmer
- Course(s) :
- BIT
Blood Group : B+
Posts : 209
Points : 328
IITDU Forum :: Academics (BIT) :: Semester 2 :: SE 205
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Tue Sep 29, 2015 2:45 pm by Sophiawood
» Cisco EHWIC SFP/GE WAN Card
Mon Sep 07, 2015 11:08 am by Sophiawood
» Huawei S1700-28GFR-4P-AC Price
Thu Jun 25, 2015 2:31 pm by Sophiawood
» teach yourself C++ / Herbert Schildt Solutions
Wed Jun 03, 2015 1:52 pm by Abdullah Al Noman
» teach yourself c by herbert schildt pdf
Wed May 13, 2015 11:01 pm by Raquib Ridwan
» ASA 5506X With Firepower ASA5506-K9
Fri Apr 10, 2015 4:31 pm by Sophiawood
» New Trends in Deal Business
Tue Feb 03, 2015 9:38 pm by nersoa
» PoE Power Allocation for WS-C2960S-24PS-L
Wed Nov 05, 2014 11:12 am by Sophiawood
» How to cure back pain
Fri Oct 31, 2014 7:15 pm by Bergen Guildford