genskill.cpp
./skill/genskill.cpp · 2.4 KB
From the archive skills.tar.gz
Download the archive « Back to the archive contents
#include <fstream>
#include <iostream>
using namespace std;
#define FROM_MUD_H "frommud.txt"
#define CMD_LST "skill.list"
int main()
{
void open_file(ifstream& fin,ofstream& fout);
void read_file(ifstream& fin,ofstream& fout);
ifstream fin;
ofstream fout;
open_file(fin,fout);
read_file(fin,fout);
return 0;
}
void open_file(ifstream& fin,ofstream& fout)
{
fin.open(FROM_MUD_H);
if(!fin)
{
cout<<"\n File \""<<FROM_MUD_H<<"\" could not be opened.\n"
<<" Program will now exit.\n";
exit(0);
}
fout.open(CMD_LST);
if(!fout)
{
cout<<"\n File \""<<CMD_LST<<"\" could not be opened.\n"
<<" Program will now exit.\n";
exit(0);
}
}
#define MAX_E 100
void read_file(ifstream& fin,ofstream& fout)
{
int find_txt(string ,char [MAX_E]);
int find_non_letter(string ,string& );
string text;
string cmd;
string cmd2;
string last=" ";
int end=0;
while( getline(fin,text) )
{
end=(find_txt(text,");")-19);
cmd2=text.substr(19,end);
end=find_non_letter(cmd2,cmd);
fout<<cmd<<"\n";
text.erase();
cmd2.erase();
cmd.erase();
}
}
int find_non_letter(string x,string& cmd)
{
int result;
for(int i=0;i<x.length();++i)
{
if( x.at(i) == 'a' || x.at(i) == 'b' || x.at(i) == 'c' || x.at(i) == 'd' ||
x.at(i) == 'e' || x.at(i) == 'f' || x.at(i) == 'g' || x.at(i) == 'h' ||
x.at(i) == 'i' || x.at(i) == 'j' || x.at(i) == 'k' || x.at(i) == 'l' ||
x.at(i) == 'm' || x.at(i) == 'n' || x.at(i) == 'o' || x.at(i) == 'p' ||
x.at(i) == 'q' || x.at(i) == 'r' || x.at(i) == 's' || x.at(i) == 't' ||
x.at(i) == 'u' || x.at(i) == 'v' || x.at(i) == 'w' || x.at(i) == 'x' ||
x.at(i) == 'y' || x.at(i) == 'z' || x.at(i) == '_' || x.at(i) == '1' ||
x.at(i) == '2' || x.at(i) == '3' || x.at(i) == '4' || x.at(i) == '5' ||
x.at(i) == '6' || x.at(i) == '7' || x.at(i) == '8' || x.at(i) == '9' ||
x.at(i) == '0' )
{
cmd+=x.at(i);
}
else
result = i;
}
cout<<cmd<<" result= "<<result<<"\n";
return result;
}
int find_txt(string x,char y[MAX_E])
{
cout<<"\n"<<x;
int result=0;
for(int i=0;i<x.length();++i)
{
if(x.at(i) == y[0] && x.at(i+1) == y[1] )
{
result = i;
}
}
if(result==0)
{
cout<<"ERROR";
exit(0);
}
return result;
}