Exemple #1
0
int
removeWord (trieNode **root, char *word)
{
	if (*word == '\0')
	{
		(*root)->isleaf = false;
		if ( isLeafNode(*root) )
			return 1;
		else 
			return 0;
	}
	for (int i = 0; i < ALPHABET_SIZE; i++)
	{
		int index = char2ascii(*word);
		if ((*root)->next[index])
		{
			if (removeWord((*root)->next[index], word + 1))
			{
				removeNode((*root)->next[index]);
				return 1;
			}
			break;
		}
	}
	return 0;
}
Exemple #2
0
int main( void )
{
	char *text;
	int num;
	int readed;

	puts( "Enter text:" );
	text = Input();

	for( ;; )
	{
		puts( "Enter number:" );
		readed = scanf( "%d", &num );
		if( readed > 0 && num >0 )
		{
			break;
		}
		else
		{
			puts( "Wrong number" );
		}
	}

	removeWord( text, (size_t)num );

	puts( text );

	return 0;
}
Exemple #3
0
int afficheMenu(char* dic[])
{
    switch (myMenu())
    {
    case 1:
        printf("\nComparaison de 2 mots :\n\n");
        wordIhm();
        break;
    case 2:
        printf("Comparaison et tri\n\n");
        sortMyArr();
    case 3:
        printf("Rechercher un mot dans le dictionnaire\n\n");
        compareWords(dic);
        break;
    case 4:
        printf("Ajouter un mot dans le dictionnaire\n\n");
        addWord(dic);
        break;
    case 5:
        printf("Supprimer un mot\n\n");
        removeWord(dic);
        break;
    case 6:
        printf("Trier un tableau\n\n");
        sortAnArr();
    case 7:
        printf("Quitter");
        return 1;
    default:
        printf("Quitter");
        return 1;
    }
    return 0;
}
Exemple #4
0
int
main()
{
  Words * w1 = newList(10);
  appendList(w1, "caterpie raichu butterfree");
  printList(w1); // caterpie raichu butterfree

  Words * w2 = newList("charmeleon mewtwo pikachu charmander");
  printList(w2); // charmeleon mewtwo pikachu charmander

  appendList(w2, w1);
  printList(w2); // charmeleon mewtwo pikachu charmander caterpie raichu butterfree

  appendList(w2, "abra");
  printList(w2); // charmeleon mewtwo pikachu charmander caterpie raichu butterfree abra

  removeWord(w2, "charmeleon");
  printList(w2); // mewtwo pikachu charmander caterpie raichu butterfree abra

  deleteList(w1);
  deleteList(w2);

  return 0;
}
int main()
{
    FILE * fin = NULL;
    char fn[MAX], input[MAX], word[MAX];
    int choice = 0;
    int sentSize = 5;
    int aSize, nSize, vSize, pSize;
    char ** articles = NULL;
    char ** nouns = NULL;
    char ** verbs = NULL;
    char ** preps = NULL;
    char ** sentence = NULL;

    srand(time(NULL));

    readFileName(fn);
    openFile(fn, fin, &aSize, &nSize, &vSize, &pSize);
    articles = fillArray(fn,"article", articles, aSize, fin);
    nouns = fillArray(fn,"noun", nouns, aSize, fin);
    verbs = fillArray(fn,"verb", verbs, aSize, fin);
    preps = fillArray(fn,"preposition", preps, aSize, fin);
    displayAmounts(aSize, nSize, vSize, pSize);

    sortStringArray(articles, aSize);
    sortStringArray(nouns, nSize);
    sortStringArray(verbs, vSize);
    sortStringArray(preps, pSize);

     do
	{
		choice = menu();

		if(choice == 1)
		{
			sentence = createSentence(articles, nouns, verbs, preps, aSize, nSize, vSize, pSize);
			printArray2D(sentence,sentSize);

		}// end choice == 1

		else if(choice == 2)
		{
			displayAllWords(articles, nouns, verbs, preps, aSize, nSize, vSize, pSize);
		}// end choice == 2

		else if(choice == 3)
		{
            whichArray(input);
		    whatWord(word);
		    if(strcmp(input,"ARTICLES") == 0)
                addWord(articles, word, &aSize);
            else if(strcmp(input,"NOUNS") == 0)
                addWord(nouns, word, &nSize);
            else if(strcmp(input,"VERBS") == 0)
                addWord(verbs, word, &vSize);
            else if(strcmp(input,"PREPOSITIONS") == 0)
                addWord(preps, word, &pSize);
		}// end choice == 3

		else if(choice == 4)
		{
			whichArray(input);
			whatWord(word);
            if(strcmp(input,"ARTICLES") == 0)
                removeWord(articles, word, &aSize);
            else if(strcmp(input,"NOUNS") == 0)
                removeWord(nouns, word, &nSize);
            else if(strcmp(input,"VERBS") == 0)
                removeWord(verbs, word, &vSize);
            else if(strcmp(input,"PREPOSITIONS") == 0)
                removeWord(preps, word, &pSize);

		}// end choice == 4

		else if(choice == 5)
		{
            displayTogetherSorted(articles, nouns, verbs, preps, aSize, nSize, vSize, pSize);
		}// end choice == 5

	}while(choice != 6);

    return 0;
}
Exemple #6
0
void menu(char ***array, int *wordCount, int *capacity)
{
  int exit;
  char option;
  char word[WORD_LENGTH];
  
  exit = 0;
  do 
  {
    printf("\nMenu\n");
    printf("'S'earch, 'I'nsert, 'R'emove, 'C'ount, 'P'rint, 'Q'uit\n");
    scanf("%c", &option);
    /* takes in char + newline character
       see "newline handler" below
    */
    if (option == 's' || option == 'S')
    {
      /* call search() */
      printf("\nSearch\n");
      searchWord(array, wordCount);
    } 
    else if (option == 'i' || option == 'I') 
    {
      /* call insert() */
      printf("\nInsert\n");
      printf("\nEnter a word: ");
      scanf("%s", word);
      insertWord(array, wordCount, word, capacity);
      printf("\nWord inserted.\n");
    } 
    else if (option == 'r' || option == 'R') 
    {
      /* call remove() */
      printf("\nRemove\n");
      removeWord(array, wordCount);
    } 
    else if (option == 'c' || option == 'C') 
    {
      /* call count() */
      printf("\nCount\n");
      printCount(*wordCount);
    } 
    else if (option == 'p' || option == 'P') 
    {
      printf("\nPrint\n");
      printArray(*array, *wordCount);
    } 
    else if (option == 'q' || option == 'Q') 
    {
      exit = 1;
    } 
    else 
    {
      /* invalid entry */
      printf("\nInvalid Entry, returning to main menu\n");
    }
    /* newline handler */
    while (option != '\n') 
    {
      scanf("%c", &option);
    }
  } 
  while (exit == 0);
}