tree.c 1.49 KB
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

typedef struct noeud * Noeud;
struct noeud { char valeur ; Noeud fils[26]; Noeud complet;};
struct dico { struct noeud * tableau[26];};



void cons_noeud (Noeud * pN, char a)
{	int i;
    *pN =malloc( sizeof(struct noeud));
    (*pN)->valeur=a;
    (*pN)->complet=NULL;
    for(i=0; i<26; i++)
        (*pN)->fils[i]=NULL;
}

void ajout_mot_noeud (Noeud * pN, char *mot)
{
    int i;
    int n=strlen(mot);
    if(*pN == NULL) cons_noeud(pN, tolower(mot[0]));
    for(i=1; i<n; i++){
    	pN=&(*pN)->fils[tolower(mot[i])-97];
    	if(&(*pN)->valeur==NULL) 
    		cons_noeud(pN, tolower(mot[i]));
      }cons_noeud(&(*pN)->complet,49);
}
    

void ajout_noeud_dico(struct dico * D, Noeud N)
{
    int i=0;
    while(D->tableau[i]!=NULL)
    {i++;}
    D->tableau[i]=N;
}



void cons_dico_file(char * nomfichier, struct dico* D)
{ 
    int i;
    char * mot;
    FILE * fp;
    fp=fopen(nomfichier, "r");
  if(fp==NULL)
    return;
  while((fscanf(fp,"%s",mot)==1))
    {
        ajout_mot_noeud(&(D->tableau[mot[i]-97]),mot);
        i++;
    
    }
}

int appartient_dico(struct dico D,char * mot)
{
    
}



void correction_texte(char* nomfichier, struct dico D)
{
    FILE *fp;
    fp=fopen(nomfichier, "r+");
    char * mot;
    if(fp==NULL)
    return;
  while((fscanf(fp,"%s",mot)==1))
  {
      if(appartient_dico(D,mot)==1)
          return;
      else
          printf("%s\n"mot);
  }
}

int main()
{
    
    return 0;
}