Exemple #1
0
void exist_word(No* a_root, char* a_word){
	//-------------------------------------------------------------
	//Retorno:
	//			bool : true = palavra achada
	//					false = palavra não achada
	//
	//Argumentos:
	//			No* a_root: nó da arvore
	//			char* a_word: auxiliar de string
	//
	//Descrição da função:
	//			Varre toda a arvore Trie, imprimindo as palavras encontradas
	//-------------------------------------------------------------


	if(a_root == NULL)//Caso a arvore esteja nula, só ocorre na inicialização
		return;
	else {

		int i;
		if(a_root->exists!=NULL)
			if(a_root->line != NULL){//Se a palavra existe e ocorreu no texto, mostre!
				printf("%s %d",a_root->exists,a_root->line[0]);
				for(i=1;a_root->line[i]!='\0';i++)
					printf(", %d",a_root->line[i]);

				printf("\n");
			}

		for(i = 0 ; i<c_alphabet_length; i++)//Continue procurando em cada filho
			if(a_root->sheet[i]!= NULL)
				exist_word(a_root->sheet[i],append(a_word,'a'+i));
	}

	return;

}
Exemple #2
0
int	suppr_word(noeud *racine, char *mot)
{
  int	i;
  int	size;
  int	newsize;
  char	*terme;
  noeud *word;

  size = strlen(mot)-1;
  newsize = size+1;
  if (exist_word(racine,mot) == NON){
    printf("%s  n'existe pas dans le dictionnaire\n", mot);
    return (EXIT_FAILURE);
  }
  word = return_letter(racine, mot);
if (exist_fils(word)){
    word->fin_de_mot = NON;
    printf("%s supprimé\n",mot);
    return (EXIT_SUCCESS);
    };
 
  for (i = 0; i < size; i++)
    {
      terme = xmalloc(sizeof(char)*newsize + 1);
      terme = strncpy(terme,mot,newsize);
      terme[newsize] = '\0';
      word = return_letter(racine, terme);
      printf("word->letter %c %d\n",word->lettre, exist_fils(word));
      if (exist_fils(word) == 0){
	word->fin_de_mot = NON;
	free(word);
      }
      free(terme);
      newsize--;
      }
  return (EXIT_SUCCESS);
}
Exemple #3
0
int main(int argc, char **argv) {


	if(argc >= 1){//Mudar dps para 3<<<<<<<<<<<<<<<<<<<<<<<<<

		initialize_dictionary(argv[1]);

		initialize_text(argv[2]);


//TODO
		//1 - ver o lance do malloc do append(segmentation fault




		exist_word(gno_root_dictionary,NULL);//Mostra a saída
		show_list(gno_sugestion);

	}else{
		printf("Bad arguments");
	}
	return 0;
}