FSM spellchecker
Posted
by Durell
on Stack Overflow
See other posts from Stack Overflow
or by Durell
Published on 2010-03-13T04:30:56Z
Indexed on
2010/03/13
4:37 UTC
Read the original article
Hit count: 414
fsm
I would love to have a debugged copy of the finite state machine code below. I tried debugging but could not, all the machine has to do is to spell check the word "and",an equivalent program using case is welcomed.
#include<cstdlib>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
using namespace std;
char in_str;
int n;
void spell_check()
{
char data[256];
int i;
FILE *in_file;
in_file=fopen("C:\\Users\\mytorinna\\Desktop\\a.txt","r+");
while (!feof(in_file))
{
for(i=0;i<256;i++)
{
fscanf(in_file,"%c",in_str);
data[i]=in_str;
}
//n = strlen(in_str);
//start(data);
cout<<data;
}
}
void start(char data)
{
// char next_char;
//int i = 0;
// for(i=0;i<256;i++)
// if (n == 0)
{
if(data[i]="a")
{
state_A();
exit;
}
else
{
cout<<"I am comming";
}
// cout<<"This is an empty string";
// exit();//do something here to terminate the program
}
}
void state_A(int i)
{
if(in_str[i] == 'n')
{
i++;
if(i<n) state_AN(i);
else error();
}
else error();
}
void state_AN(int i)
{
if(in_str[i] == 'd')
{
if(i == n-1)
cout<<" Your keyword spelling is correct";
else
cout<<"Wrong keyword spelling";
}
}
int main()
{
spell_check();
system("pause");
return 0;
}
© Stack Overflow or respective owner