Contactnomanakhter.com

Noman Akhter

Technology · Business · Tutorials
Education

How to tokenize a Pascal Program through file open

#include <conio.h>
#include <ctype.h>
#include <stdio.h>
#include <dos.h>
#include <Process.h>
#include <Stdlib.h>
#include <io.h>
#include <string.h>

void main ()
{
FILE *fs, *ft;
char ch, cha;
//char st[250];
char charray[50000];
clrscr();
int i;
i=0;

//WELCOME MESSAGE
    printf ("This program will tokenize a Pascal program\n");
        //READING A FILE

    if(access("MYFILE.TXT",0)==0)
    {

        fs = fopen("MYFILE.TXT","r");
            if (fs == NULL)
                {
                    puts ("Cannot open source file");
                    getch();
                    exit(0);
                }
        ft = fopen ("YOURFILE.TXT", "w" );
            if (ft == NULL)
                {
                    puts ("Cannot open target file");
                    fclose ( fs );
                    getch();
                    exit(0);
                }
        while ( 1 )
                {
                        ch = fgetc ( fs );
                        if ( ch == EOF )
                        break;
                        else
                        if(isspace(ch)||ch=='`'||ch=='~'||ch=='!'||ch=='@'||ch=='#'||ch=='$'||ch=='%'||ch=='^'||ch=='&'||ch=='*'||ch=='('||ch==')'||ch=='-'||ch=='_'||ch=='='||ch=='+'||ch=='\n'||ch=='\\'||ch=='|'||ch==']'||ch=='}'||ch=='['||ch=='{'||ch=='\''||ch=='\"'||ch=='\;'||ch=='\:'||ch=='?'||ch=='\/'||ch=='\.'||ch=='>'||ch==','||ch=='<'||ch=='\"'||ch=='\t')
                        {
                        putc ( ch, ft );
                        charray[i]= ch;
                        printf("%c\n",charray[i]);
                        }
                        else
                        {
                        putc ( ch, ft );
                        charray[i]= ch;
                        printf("%c",charray[i]);
                        }
                i++;
                }
        fclose ( fs );
        i--;
        fprintf(ft, "\nTotal Characters: %d", i);
        fclose (ft);
        }
    else
    {
    printf("Not allowed");
    }
getch();
}
Noman Akhter

Written by Noman Akhter (Startups Coach)

Online business expert and IT consultant since 2005. Founder of NAFsols and Startups Pakistan. More at nomanakhter.com.

Comments

Post a Comment