Affichage du conntenu d'une liste chainée C
stroumpf
Messages postés
292
Statut
Membre
-
stroumpf Messages postés 292 Statut Membre -
stroumpf Messages postés 292 Statut Membre -
Bonjour,
J'ai un probleme, ( je developpe en C)
j'ai une fonction qui parcourt toute la liste chainee qui contient des mots , jai reussi à faire l'affichage de la liste mais le probleme c'est qu'il n ya pas un espace entre les differents mot :(
exple il affiche "lebateau " au lieu du "le bateau".
j'attends vos reponse.
merci
J'ai un probleme, ( je developpe en C)
j'ai une fonction qui parcourt toute la liste chainee qui contient des mots , jai reussi à faire l'affichage de la liste mais le probleme c'est qu'il n ya pas un espace entre les differents mot :(
exple il affiche "lebateau " au lieu du "le bateau".
j'attends vos reponse.
merci
Configuration: Windows XP Internet Explorer 7.0
4 réponses
-
int main() { FILE *F; char mot[100]; int i; unsigned int cle,pt; int nl, pos; nl=pos=1; char c; int seuil; Liste **L; Liste **TableHash; TableHash = (Liste **) malloc (TAILLEHASH * sizeof(Liste *)); for(i=0;i<TAILLEHASH;++i) TableHash[i] = NULL; pt=hash_cle("."); //printf("%d",pt); printf("debut du programme \n----------------------------------\n"); F=fopen("C:\\Documents and Settings\\siril\\Bureau\\projet\\text.txt","r"); while(fscanf(F,"%s",mot)==1){ cle = hash_cle(mot); if ((cle!=pt ) && (! ChercherMotDansTableHash(TableHash,mot))) TableHash[cle] = InsertionEnTete(TableHash[cle],mot); } fclose(F ); F=fopen("C:\\Documents and Settings\\siril\\Bureau\\projet\\text.txt","r"); PosLigne(F,TableHash); //filtrage printf("\nla liste filtre :\n----------------------------------\n"); FiltreListe(TableHash,2); AfficherTableHash(TableHash); //géneration des 2seq Liste *seq=NULL; Generer2seq(TableHash, 2, &seq); printf("\nla liste des 2seq :\n----------------------------------\n"); AfficherListe(seq); scanf("%c",c); return 0; } void AfficherListe(Liste *L){ Liste *p; for(p=L;p!=NULL;p=p->suivant){ AfficheMot(p->mot); AfficherCoordonnees(p->c); } } void AfficheMot(char *mot){ printf("%s ",mot); } -
Salut,
affiche le code complet puisque j'ai oublié
et aussi le fichier sur lequel tu testes
merci -
POSTMOT.c
#include<stdio.h> #include<stdlib.h> #include<string.h> #include "table_hash.h" #define TAILLEHASH 307 int main() { FILE *F; char mot[100]; int i; unsigned int cle,pt; int nl, pos; nl=pos=1; char c; int seuil; Liste **L; Liste **TableHash; TableHash = (Liste **) malloc (TAILLEHASH * sizeof(Liste *)); for(i=0;i<TAILLEHASH;++i) TableHash[i] = NULL; pt=hash_cle("."); //printf("%d",pt); printf("debut du programme \n----------------------------------\n"); F=fopen("C:\\Documents and Settings\\siril\\Bureau\\projetcyrine\\text.txt","r"); while(fscanf(F,"%s",mot)==1){ cle = hash_cle(mot); if ((cle!=pt ) && (! ChercherMotDansTableHash(TableHash,mot))) TableHash[cle] = InsertionEnTete(TableHash[cle],mot); } fclose(F ); F=fopen("C:\\Documents and Settings\\siril\\Bureau\\projetcyrine\\text.txt","r"); PosLigne(F,TableHash); //filtrage printf("\nla liste filtre :\n----------------------------------\n"); FiltreListe(TableHash,2); AfficherTableHash(TableHash); //géneration des 2seq Liste *seq=NULL; Generer2seq(TableHash, 2, &seq); printf("\nla liste des 2seq :\n----------------------------------\n"); AfficherListe(seq); //printf("Chercher mot : "); //scanf("%s",mot); //if(cle = ChercherMotDansTableHash(TableHash,mot)) // printf("%s existant dans le conteneur %u\n",mot,hash_cle(mot)); //else // printf("%s inexistant dans la table de hash\n"); scanf("%c",c); return 0; } void ParcourirElementTableHash(Liste **TableHash,char *mot){ int cle; Liste *p; cle = hash_cle(mot); for(p=TableHash[cle];p!=NULL;p=p->suivant) if(strcmp(mot,p->mot) == 0){ printf("%s : ",mot); AfficherCoordonnees(p->c); } } Liste *InsertionEnTete(Liste *L,char *mot){ Liste *nouveau; nouveau = (Liste *) malloc (sizeof(Liste)); strcpy(nouveau->mot,mot); nouveau->suivant = L; nouveau->c = NULL; return nouveau; } Coordonnees *InsertionEnTeteCoordonnee(Coordonnees *C,int nl ,int pos){ Coordonnees *nouveau; nouveau = (Coordonnees *) malloc (sizeof(Coordonnees)); nouveau->pos = pos; nouveau->nl = nl; nouveau->suivant = C; return nouveau; } void AfficherListe(Liste *L){ Liste *p; for(p=L;p!=NULL;p=p->suivant){ AfficheMot(p->mot); AfficherCoordonnees(p->c); } } void AfficherCoordonnees(Coordonnees *C){ Coordonnees *p; for(p=C;p!=NULL;p=p->suivant) printf(" (%d,%d) ",p->nl,p->pos); printf("\n"); } void AfficheMot(char *mot){ printf("%s ",mot," "); } unsigned int hash_cle(char *mot){ unsigned int val = 0; for(;*mot!='\0';++mot) val = *mot + 31 * val; return val % TAILLEHASH; } void AfficherTableHash(Liste **TableHash){ int i; for(i=0;i<TAILLEHASH;++i) if(TableHash[i] != NULL){ printf("Conteneur %d \n",i); AfficherListe(TableHash[i]); printf("----------------------------------\n"); } } unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot){ Liste *p; unsigned int cle; cle = hash_cle(mot); for(p=TableHash[cle];p!=NULL;p=p->suivant) if(strcmp(p->mot,mot)==0) return 1; return 0; } void FiltreListe(Liste **TableHash, int seuil){ Liste *p ,*last; Coordonnees *c; int i,supp=0,nb=0; for(i=0;i<TAILLEHASH;++i) if(TableHash[i] != NULL){ nb=0; last=TableHash[i]; for(p=TableHash[i];p!=NULL;p=p->suivant){ supp=0; nb++; for(c=p->c;c!=NULL;c=c->suivant) supp++; if( supp <seuil){ // mot n'est pas frequent if (last==p) // cas du première mot { TableHash[i]=p->suivant; last=p->suivant; } else last->suivant=p->suivant; nb--; }else last=p; } if (nb==0) TableHash[i] = NULL; } } void Generer2seq(Liste **TableHash, int seuil, Liste **seq){ Liste *p1, *p2, *ss,*t; Coordonnees *c1,*c2; int i,j,supp1=0,supp2=0,nb=0; char s1[50], s2[50],*t1,*t2; ss=*seq; printf("\nconstruction des 2seq \n---------------\n"); for(i=0;i<TAILLEHASH;++i) if(TableHash[i] != NULL) for(p1=TableHash[i];p1!=NULL;p1=p1->suivant) for(j=i;j<TAILLEHASH;++j) if(TableHash[j] != NULL){ if (j==i) t=p1; else t=TableHash[j]; for(p2=t;p2!=NULL;p2=p2->suivant){ if (strcmp(p1->mot,p2->mot)!=0){ // si 2 mots differents trouvés Liste *tmp1=NULL, *tmp2=NULL; strcpy(s1,p1->mot); strcpy(s2,p2->mot); t1=strcat(s1,p2->mot); t2=strcat(s2,p1->mot); tmp1=InsertionEnTete(tmp1,s1); tmp2=InsertionEnTete(tmp2,s2); printf("creation TMP1 et TMP2 : %s ,%s\n",s1,s2); supp1=0;supp2=0; for(c1=p1->c;c1!=NULL;c1=c1->suivant) // calcule de supp for(c2=p2->c;c2!=NULL;c2=c2->suivant){ if (c1->nl == c2->nl){ if(c1->pos < c2->pos){ tmp1->c=InsertionEnTeteCoordonnee(tmp1->c,c1->nl ,c2->pos); supp1++; } else{ tmp2->c=InsertionEnTeteCoordonnee(tmp2->c,c1->nl ,c1->pos); supp2++; } } } // fin calcul supp if(supp1>=seuil){ //printf("%d ",supp1); if (*seq==NULL) *seq=tmp1; else ss->suivant=tmp1; ss=tmp1; //printf("%s : OK1\n",tmp1->mot); } if(supp2>=seuil){ //printf("%d ",supp2); if (*seq==NULL) *seq=tmp2; else ss->suivant=tmp2; ss=tmp2; //printf("%s : OK2\n",tmp2->mot); } } // fin de traitement des mot //printf("fin"); } } printf("////fin calcule 2seq\n"); } void PosLigne(FILE *F,Liste **TableHash){ char s[50]; int nl,pos,i; Liste *p; nl=pos=1; while(fscanf(F,"%s",s)==1){ for(i=0;i<TAILLEHASH;++i) if(TableHash[i]!=NULL) for(p=TableHash[i];p!=NULL;p=p->suivant) if(strcmp(p->mot,s)==0) p->c=InsertionEnTeteCoordonnee(p->c,nl ,pos); if(fgetc(F)=='\n'){ ++nl; pos=0; } ++pos; } printf("\n"); }
table_hash.h#ifndef TABLE_HASH #define TABLE_HASH typedef struct c{ int pos; int nl; struct c *suivant; }Coordonnees; typedef struct L{ char mot[50]; Coordonnees *c; struct L *suivant; }Liste; Liste *InsertionEnTete(Liste *L,char *mot); Coordonnees *InsertionEnTeteCoordonnee(Coordonnees *C,int nl,int pos); void AfficherListe(Liste *L); void AfficherCoordonnees(Coordonnees *C); void AfficheMot(char *mot); unsigned int hash_cle(char *mot); void AfficherTableHash(Liste **TableHash); unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot); void PosLigne(FILE *F,Liste **TableHash); void frequent( Liste **TableHash , int mc); void ParcourirElementTableHash(Liste **TableHash,char *mot); void FiltreListe(Liste **L, int seuil); void Generer2seq(Liste **TableHash, int seuil, Liste **seq); #endif
fichier texte
Support for RTSP authentication
Support for adding subtitles on the fly
Fixed MPEG-PS duration calculation
ATSC support for DVB input
Partial reading support for DVR-ms recordings
Partial reading support for MXF and GXF fileformat
Improved support for Flash Video files
ctout -
Le problème c'est ta fonction Generer2seq
Par exemple Supportfor et enregistrer comme un mot et pas deux
Je vois que tu as compliquer beaucoup ce que a déjà été fait.
J'ai mis un ; juste pour voir s'il y a un problème de séparation. Et non, le problème viens de ta fonction.debut du programme ---------------------------------- la liste filtre : ---------------------------------- Conteneur 17 Support ; (2,1) (1,1) ---------------------------------- Conteneur 95 reading ; (6,2) (5,2) ---------------------------------- Conteneur 133 Partial ; (6,1) (5,1) ---------------------------------- Conteneur 205 support ; (7,2) (6,3) (5,3) (4,2) ---------------------------------- Conteneur 267 for ; (7,3) (6,4) (5,4) (4,3) (2,2) (1,2) ---------------------------------- construction des 2seq --------------- creation TMP1 et TMP2 : Supportreading ,readingSupport creation TMP1 et TMP2 : SupportPartial ,PartialSupport creation TMP1 et TMP2 : Supportsupport ,supportSupport creation TMP1 et TMP2 : Supportfor ,forSupport creation TMP1 et TMP2 : readingPartial ,Partialreading creation TMP1 et TMP2 : readingsupport ,supportreading creation TMP1 et TMP2 : readingfor ,forreading creation TMP1 et TMP2 : Partialsupport ,supportPartial creation TMP1 et TMP2 : Partialfor ,forPartial creation TMP1 et TMP2 : supportfor ,forsupport ////fin calcule 2seq la liste des 2seq : ---------------------------------- Supportfor ; (1,2) (2,2) Partialreading ; (5,2) (6,2) readingsupport ; (5,3) (6,3) readingfor ; (5,4) (6,4) Partialsupport ; (5,3) (6,3) Partialfor ; (5,4) (6,4) supportfor ; (4,3) (5,4) (6,4) (7,3)