Exemplo n.º 1
0
void lancementSimple(char* chemin, char* name)
{
	int T[N];
	int nb_occurence[N];
	int i;
	int f,d;
	
	extentionDossierCalcul(chemin,&f,&d);
	
	char* format = malloc(sizeof(char)*(f+1));
	char* dossier = malloc(sizeof(char)*(d+1));
	
	extentionDossierCreation(chemin,format,dossier,&f,&d);	
	
	char fichierCode[strlen(dossier)+strlen(name)+4];
	char fichierRetour[strlen(dossier)+strlen(name)+1+strlen(format)];
	
	strcpy(fichierCode,dossier);
	strcat(fichierCode,name);
	strcat(fichierCode,".txt");
	
	strcpy(fichierRetour,dossier);
	strcat(fichierRetour,name);
	strcat(fichierRetour,".");
	strcat(fichierRetour,format);

	pArbre res = huffman(chemin,nb_occurence);
	for (i=0;i<N;i++){
		T[i]=0;
	}
	
	profondeur(res,T,0);

	unsigned char nb_symbole=255;
	for (i=0;i<N;i++){ if (T[i]!=0){ nb_symbole++;}}
	
	
	//calcul de la taille
	int taille=0;
	for (i=0;i<N;i++){
		taille= taille + nb_occurence[i]*T[i];
	}
	
	pArbre A=construction_arbre_canonique(T);
	
	FILE *F1= ouvertureFichierLecture(chemin);
	FILE *F2 = ouvertureFichierEcriture (fichierCode);
	
	//ecriture du nombre de symbole 
	putByte(F2,nb_symbole);
	
	codage(F1,F2,A,taille);
	
	fermetureFichier(F1);
	fermetureFichier(F2);
}
 int main(){
    int numero = 333;
    char phrase[TAILLE_MAX+3] = "abyz????????e";
    printf("Avant numérotation : %s\n", phrase);
    numerotation(phrase, numero);
    printf("Après numérotation : %s\n", phrase);
    printf("Avant codage : %s\n", phrase);
    char x = choixLettre();
    printf("Choix de la lettre : %c\n", x);
    codage(phrase, x);
    printf("Après codage : %s\n", phrase);
    decodage(phrase, x);
    printf("Après décodage : %s\n\n", phrase);
    ecrireDansFichier(phrase);
    return 0;
 }