1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#include <fstream>
#include<cstdlib>
#include <dirent.h>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
/*Indexation d'un fichier*/
bool chercherVide(string mot, string vide[]){
for(int i=0; i<50;i++){
if(vide[i] == mot){
return true;
break;
}
}
return false;
}
int main(int argc, char** argv) {
// tableau contenant les mots vides
string vide[100] = {"je","tu","il","nous","vous","ils","le","la","les","un","une","de","du","des","à","au","sur","sous","et","on","en","ou","se","ce","ça","cela","ceci"};
// fichier a parcourir
ifstream lire("indexation.txt");
// fichier d'indexation
ofstream ecrire("indexation.dat", ios_base::app);
string mot;
int position = 0 ;
int occurence = 0 ;
string occ;
while(!lire.eof()){ // boucler jusqu'à la fin du fichier
lire >> mot; // lire mot par mot
while (!lire.eof()){
lire>>mot;
if(mot.compare(lire) == 0){
occurence++;
}
}
if(!chercherVide(mot,vide)){ // vérifier si le mot est vide ou non
ecrire << mot <<" " <<position<<"\t"<<occurence<<endl;// si non, l'insérer dans le fichier d'indexation avec sa position
}
position++;
occurence =0;
}
cout<<"fichier indexé avec succès"<<endl;
return 0;
} |