How to write the main() for this program?

I have this scanner program that returns only the tokens.  The program needs to read another program that is stored in a text file, pick out the tokens, and write the tokens to another text file.  Can anyone help me on how to write the main() to use this program.  Here's the code for the program that analyses the code and returns the tokens.  Thanks!!!!!!

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream.h>

typedef enum {START,INASSIGN,INCOMMENT,INNUM,INID,DONE}
      State;

#define BMAX 256
#define MAXTL 40

static char lineBuf[BMAX];

static int linenum = 0;
static int bufsz = 0;
static int EoFflag = false;
static int linepos = 0;

 

FILE *source, *tokfile;

static int getNxChar(void)
{
       if(!(linepos < bufsz))
       {
             linenum++;
             
             if(fgets(lineBuf, BMAX-1, source))
             {
                   bufsz = strlen(lineBuf);
                   linepos = 0;
                   return lineBuf[linepos++];
             }
             else
             {
                   EoFflag = true;
                   return EOF;
             }
       }
       else
       {
             return lineBuf[linepos++];
       }
 }

 static void ungetNxChar(void)
 {
       if(!EoFflag)
             linepos--;
 }

 void getTok(void)
 {
       char tokString[MAXTL+1];
       int tokStrInd = 0;
       State state = START;

       bool keep, errflag;
      
       errflag = false;

       while (state != DONE)
       {
             int a = getNxChar();
             keep = true;

             switch(state)
             {
             case START:
                   if(isdigit(a))
                         state = INNUM;
                   else if(isalpha(a))
                         state = INID;
                   else if(a == ':')
                         state = INASSIGN;
                   else if((a == ' ')||(a == '\t')||(a == '\n'))
                         keep = false;
                   else if(a == '{')
                   {
                         keep = false;
                         state = INCOMMENT;
                   }
                   else
                   {
                         state = DONE;
                         
                         switch(a)
                         {
                         case EOF:
                               keep = false;
                               break;
                         case'=':
                               break;
                         case'<':
                               break;
                         case'>':
                               break;
                         case'(':
                               break;
                         case')':
                               break;
                         case';':
                               break;
                         case'+':
                               break;
                         case'-':
                               break;
                         case'*':
                               break;
                         case'/':
                               break;
                         default:
                               keep = false;
                               errflag = true;
                               break;
                         }
                   }
                   break;

             case INCOMMENT:
                   keep = false;
                   if(a == EOF)
                         state = DONE;
                   else if(a == '}')
                         state = START;
                   break;
             case INASSIGN:
                   state = DONE;
                   if(!(a == '='))
                   {
                         ungetNxChar();
                         keep = false;
                         errflag = true;
                   }
                   break;
             case INNUM:
                   if(!isdigit(a))
                   {
                         ungetNxChar();
                         keep = false;
                         state = DONE;
                   }
                   break;
             case INID:
                   if(!isalpha(a))
                   {
                         ungetNxChar();
                         keep = false;
                         state = DONE;
                   }
                   break;
             }

             if((keep) && (tokStrInd <= MAXTL))
                  tokString[tokStrInd++] = (char)a;
             if(state == DONE)
             {
                   tokString[tokStrInd] = '\0';
                   fprintf(tokfile,"%s\n",tokString);
             }
             if (errflag)
             {
                   fprintf(tokfile,"%s","Error in source file line number:");
                   fprintf(tokfile,"%d\n",linenum);
             }
    }

}
 
morales7_0Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

grg99Commented:
Argh, you can do it this way, with a few state variables.

But you might want to consider the clarity that comes from using loops right in the code, i.e.

if( ch == '{' ) do GetCh(); while( ch != '}' );

... and so on.  

( Just a suggestion )
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.