Hier hat mal jemand nach einem Programm gefragt, mit dem man zwei Liste kombinieren kann (Username und Passwort). Nachdem ich mit dem Programmieren fertig war, wurde der Beitrag gelöscht ... Da ich den Code jetzt aber nicht auf meiner Platte vergammeln lassen will, stelle ich ihn hier mal zur Verfügung (damit er auch hier vergammeln kann ). Programm ist in C++ und sollte eigentlich nur C++-Standard konforme Elemente enthalten.
Code:
/* makecombolist: Combines two Lists in a form like this -> list1:list2
Copyright (C) 2012 Stefan Lahner <lahner[dot]stefan[at]gmx[dot]at>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
int main(int argc, const char* argv[])
{
string ulPath, pwlPath, clPath, user, password;
ifstream userList, passwordList;
ofstream comboList;
/* Files erfragen und öffnen ... */
/* ohne Argumente */
if(argc == 1)
{
/* User-Liste öffnen */
do
{
cout << "Bitte geben sie den Pfad der User-Liste an: ";
getline(cin, ulPath);
userList.open(ulPath.c_str(), ios::in);
if(!userList)
{
cout << "Datei \"" << ulPath << "\" kann nicht gefunden/geoeffnet werden!" << endl
<< "Versuchen sie es noch einmal ..." << endl << endl;
}
}while(!userList);
/* Passwort-Liste öffnen */
do
{
cout << "Bitte geben sie den Pfad der Passwort-Liste an: ";
getline(cin, pwlPath);
passwordList.open(pwlPath.c_str(), ios::in);
if(!passwordList)
{
cout << "Datei \"" << pwlPath << "\" kann nicht gefunden/geoeffnet werden!" << endl
<< "Versuchen sie es noch einmal ..." << endl << endl;
}
}while(!passwordList);
/* Combo-Liste öffnen */
do
{
cout << "Bitte geben sie den Pfad an, wo die Combo-Liste gespeichert werden soll" << endl
<< "(Achtung, Datei wird ueberschrieben): ";
getline(cin, clPath);
comboList.open(clPath.c_str(), ios::out);
if(!comboList)
{
cout << "Datei \"" << clPath << "\" kann nicht geoeffnet werden!" << endl
<< "Versuchen sie es noch einmal ..." << endl << endl;
}
}while(!comboList);
}
/* mit Argumenten */
else if(argc == 4)
{
ulPath = argv[1];
userList.open(ulPath.c_str(), ios::in);
if(!userList)
{
cout << "Datei \"" << ulPath << "\" kann nicht geoeffnet werden!" << endl
<< "Programm wird beendet!" << endl << endl;
exit(EXIT_FAILURE);
}
pwlPath = argv[2];
passwordList.open(pwlPath.c_str(), ios::in);
if(!passwordList)
{
cout << "Datei \"" << pwlPath << "\" kann nicht geoeffnet werden!" << endl
<< "Programm wird beendet!" << endl << endl;
exit(EXIT_FAILURE);
}
clPath = argv[3];
comboList.open(clPath.c_str(), ios::out);
if(!comboList)
{
cout << "Datei \"" << clPath << "\" kann nicht geoeffnet werden!" << endl
<< "Programm wird beendet!" << endl << endl;
exit(EXIT_FAILURE);
}
}
/* falsche Anzahl an Argumenten */
else
{
cout << "Programm falsch verwendet. Entweder ohne Parameter oder mit 3 Parametern." << endl
<< "1. Parameter: Pfad der User-Liste" << endl
<< "2. Parameter: Pfad der Passwort-Liste" << endl
<< "3. Parameter: Pfad wo die Combo-Liste gespeichert werden soll (Achtung, Datei wird ueberschrieben)" << endl << endl;
exit(EXIT_FAILURE);
}
/* Anzahl der User (Fortschrittsanzeige) */
int userCounter = 0;
while(!userList.eof())
{
getline(userList, user);
if(!user.empty())
{
userCounter++;
}
}
userList.clear();
userList.seekg (0, ios::beg);
/* Berechnung der Fortschrittsanzeige */
float step = static_cast<float>(100)/userCounter;
/* Liste kombinieren ... */
float progress = 0;
while(!userList.eof())
{
getline(userList, user);
if(!user.empty())
{
cout << fixed << setprecision (2) << progress << "% geschafft ..." << endl;
while(!passwordList.eof())
{
getline(passwordList, password);
if(!password.empty())
{
comboList << user << ':' << password << endl;
}
}
/* Passowrt-Liste zurücksetzen */
passwordList.clear();
passwordList.seekg (0, ios::beg);
progress += step;
}
}
/* Programm beenden ... */
userList.close();
passwordList.close();
comboList.close();
return 0;
}
PS: Mir ist klar, dass es bereits solche Programme gibt (wahrscheinlich auch noch besser und schneller gelöst), aber es kann ja sein, dass jemand wissen will, wie so etwas ungefähr Funktioniert (und wie man sieht steckt nicht viel Hexerei dahinter). Sollte ein Moderator meinen, dass es eher in den Bereich Programmierung (oder sonst etwas passt) dann darf er den Beitrag natürlich verschieben