dimanche 28 juin 2015

Finite State Machine In C

I am trying to create a simple finite state machine in C and I'm quite confused on how to get started. I tried looking online but nothing has really cleared this up for me.

My goal is to check if a string is octal, hex or an integer.

My attempt at creating the states would be:

typedef enum  {
   ERROR,
   OCTAL,
   HEX,
   INTEGER
} stringStates;

Now, I would then use a switch statement to go through the entirety of the string and switch between the different states until I have correctly identified which state it belongs to.

 while (current_Position<=end_String-1)
 {
    switch( "input something here")
      {
        case 0:
             //process string
             break;
        case 1:
             //process string
             break;

         case 2:
             //process string
             break;
         case 3:
             //process string
             break;
         default:
             break;
      }
  }

This concept is still very new to me and I'm having hard time understanding its implementation. If anyone can shed some light, it'll be much appreciated.

Aucun commentaire:

Enregistrer un commentaire