Search a string in a text file in C

Hello guys,
i want some help please in coding that program , " A mini dictionary"

the file looks like :

 Waver     ---       To be hesitated
 retirement ---       life after end of career

The user enter the word , and then it prints the meaning of it

Is this a homework assignment?

If not, is the intent that your program will read the dictionary into memory and repeatedly search for words entered by the user, or that your program will search for a single word in your dictionary and exit? Does the user have supply the leading and trailing spaces before the separating --- in your dictionary. Does the user have to match case as it appears in your dictionary, or is your program supposed to do a case insensitive search?

What have you tried so far?

1 Like

No , it's not. It's a project in my college

i used that "---" only to separate words and meanings , it will appear in the program as a Space
The mini-dictionary already has words and their corresponding meanings. The
user input a sentence (string of characters) to perform one of the following
operations on it.

The Operations are:

  • Separate sentence into tokens (i.e. separate words)
  • Get the frequency of each word (i.e. number of repetitions of each word),
    from the sentence.
  • Display the corresponding meaning, from the dictionary, for each unrepeated
    token (a word) in given sentence.

And ask the user if he wants to perform any additional operation on this sentence

  • If yes, let him choose another operation.
  • If no, ask the user if he wants to enter a new sentence.
    -If yes, display the menu from beginning and ask him to enter a new
    sentence
  • if no, exit from the program

If this isn't homework, why use C? A higher level language is a much better fit.

Regards,
Alister

That what i had tried till now.

#include <stdio.h>
#include <stdlib.h>
int main()
 {
     char sentence[30];
    int operation;
    char *ptr;
    printf ("\n\n                              USER MENU...\n\n\n");
    printf ("1 - Press Number 1 to Separate sentence into tokens.\n\n");
    printf ("2 - Press Number 2 to get the frequency of each word.\n\n");
    printf ("3 - Press Number 3 to display the corresponding meaning, from the dictionary.\n\n\n");
    printf("Enter The Sentence First ....\n\n ");
    gets(sentence);
    printf ("\n\n");
    printf ("Choose the operation you want from USER MENU...\n\n");
    scanf ("%d",&operation);
    printf ("\n");
    switch (operation)
    {
    case 1:
         ptr = strtok (sentence," .");
  while (ptr != NULL)
  {
    printf ("%s\n",ptr);
    ptr = strtok (NULL, " .");
  }
  break;
    }



    return 0;
}

Sorry for long comment

---------- Post updated at 09:22 AM ---------- Previous update was at 09:19 AM ----------

I have asked many which language to learn first , they told me to learn C firstly :slight_smile: