Source > dictionary



  • Hails!

    Hab gestern ein Proggy gefunden, welches mögliche Anagramme zu einem string ausgibt. Dazu benutzt es das Systemdictionary. Da soetwas in Form eines textfiles unter Win nicht existiert, hab ich mir ein proggy geschrieben, welches eines erstellt:

    #include <ctype.h>
    #include <alloc.h>
    #include <fstream.h>
    #include <string.h>
    #include <iostream.h>
    
    int main(int argc, char* argv[])
    {
    	if(argc!=3)
          {
    		cout<<"Usage: MDIR [infile] [outfile]"<<endl;
    		return 0;
    	}
    	ifstream infile;
    	infile.open(argv[1], ios::in|ios::binary);
    	if(!infile.good())
          {
    		cout<<"Cannot open "<<argv[1]<<" for input!"<<endl;
    		return 0;
    	}
    	ofstream outfile;
    	outfile.open(argv[2], ios::out);
    	if(!outfile.good())
          {
    		cout<<"Cannot open "<<argv[2]<<" for output!"<<endl;
    		return 0;
    	}
    	char buffer;
    	int counter;
    	char *strWord;
    	infile.seekg(0);
    	cout<<"Start: "<<endl;
    	do {
    		infile.read(&buffer, 1);
    		if(isalpha(buffer))
                {
    			counter=1;
    			do {
    				infile.read(&buffer, 1);
    				counter++;
    			} while(isalpha(buffer));
    
    			infile.seekg(-counter, ios::cur);
    			strWord = (char*)malloc((counter)*sizeof(char));
    			infile.read(strWord, counter-1);
    			strWord[counter-1]='\0';
    
    			if(strlen(strWord)>3)
                      {
    				outfile.write(strWord, counter);
    				outfile<<"\n";
    			}
    			free(strWord);
    		}
    	} while(!infile.eof());
    
    	infile.close();
    	outfile.close();
    	return 0;
    }
    

    Für alle, die es nutzen wollen/können! have fun 😉
    Anregungen ebenfalls erwünscht!


Anmelden zum Antworten