Last active
August 29, 2015 14:23
-
-
Save KaterineM/be0bb9cd29848336a301 to your computer and use it in GitHub Desktop.
This program creates a new file with the union of the words of two input files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copyright (C) 2015 Katerine Muñoz Tello <[email protected]> | |
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 | |
(at your option) 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/>. | |
*** Nombre: Katerine Muñoz Tello. | |
*** Objetivo: Genere un nuevo archivo que contenga la unión de las palabras de ambos archivos. | |
*** SO: Ubuntu 15.04 | |
*** IDE: Sublime text 3. | |
*** Compilador: gcc version 4.9.2 (Ubuntu 4.9.2-10ubuntu13). | |
*/ | |
#include <iostream> | |
#include <string> | |
#include <fstream> | |
#include <stdlib.h> | |
using namespace std; | |
void agregarTexto(string palabra); | |
int Iguales(string palabra, ifstream &file); | |
int main(){ | |
string palabra, palabra2; | |
ifstream texto1; | |
ifstream texto2; | |
texto1.open("texto3.txt"); | |
texto2.open("texto4.txt"); | |
if(texto1.fail() && texto2.fail()){ | |
cout << "El archivo no existe."; | |
system("PAUSE"); | |
exit (1); | |
} | |
else{ | |
while(texto1 >> palabra){ | |
agregarTexto(palabra); | |
} | |
while(texto2 >> palabra2){ | |
agregarTexto(palabra2); | |
} | |
} | |
texto1.close(); | |
texto2.close(); | |
return 0; | |
} | |
void agregarTexto(string palabra){ | |
string en_archivo; | |
int incluir = 1; | |
fstream newfile; | |
newfile.open("texto_union.txt", ios::in); | |
while(newfile >> en_archivo){ | |
if(palabra == en_archivo){ | |
incluir = 0; | |
} | |
} | |
if(incluir == 1){ | |
newfile.close(); | |
newfile.open("texto_union.txt", ios::app); | |
newfile << palabra << "\t"; | |
} | |
newfile.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Disclaimer
I know is a really bad habit for me to code in both spanish and english (as you may see, there're variables on those languages) BUT I'm coding in C++ since the begining of the year, so, excuse me please :)