debugging finite state machine spell checker code
Posted
by Durell
on Stack Overflow
See other posts from Stack Overflow
or by Durell
Published on 2010-03-13T01:25:48Z
Indexed on
2010/03/13
1:27 UTC
Read the original article
Hit count: 406
fsm
I need someone to debug the lines of c++ code I wrote below so it can run. It is intended to spell check the word "and" using state to state transition.
include
include
using namespace std;
string in_str; int n; void spell_check() { int i; FILE *in_file;
while (!EOF(in_file))
{
fscanf(in_str);
n = strlen(in_str);
start(in_str,n);
}
}
void start() { char next_char;
int i = 0;
if (n == 0)
{
cout<<"This is an empty string";
exit();//do something here to terminate the program
}
else{
next_char = in_str[i];
if(next_char == 'a')
{
i++;
if(i >= n) error();
else state_A(i);
}
else error();
}
}
void state_A(int i) { if(in_str[i] == 'n') { i++; if(i
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(); return 0; }
© Stack Overflow or respective owner