#include <vcl.h>
#include <windows.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream.h>
#pragma hdrstop
using namespace std;
string pr[100];
string p[]={"real", "byte", "readln", "exp", "keypressed", "writeln", "clrscr", "until", "repeat", "program", "uses", "var", "begin", "then", "if", "else", "function", "end.", "end"};
#pragma argsused
int main()
{
SetConsoleTitle("Работа с файлами");
FILE *F;
FILE *Fout;
char buf[500], s;
int n=300, j=0;
char * patch = new char[300];
char * token = new char[500];
cout << "File name: ";
cin >> patch;
patch="test.txt";
if ((F=fopen(patch, "r+t"))==NULL)
{
cerr << "File not open!";
return 0;
}
if ((Fout=fopen("out.txt", "w+t"))==NULL)
{
cerr << "File not open!";
return 0;
}
token=NULL;
while(fgets(buf, n, F)!=NULL) {
bool first=true;
while((token=strtok(first? buf : NULL, " 1234567890'><+*,-/:=();\n"))!=NULL)
{
bool t=true;
first=false;
for (int i=0;i<=18; i++)
if (strcmp(token, p[i].c_str())==0)
{ t=false; break; }
for (int i=0;i<j;i++)
if (strcmp(token, pr[i].c_str())==0)
{ t=false; break; }
if (t==true) {
pr[j]=token;
fputs(token, Fout);
fputs("\n", Fout);
j++; }
}
}
fclose(F);
fclose(Fout);
if (j>0) cout << "Zapicano indefikatorov: " << j;
else if (j==0) cout << "net indefikatorov";
fflush(stdin);
cin.get();
return 0;
}
|