Find a word in a word array

Lakaiz -  
[Dal] Posted messages 6122 Registration date   Status Contributor Last intervention   -
Hello,

I am currently working on a C program to create an automatic email. I need to create a function that will find a keyword within the body of my email.
The body of my email is an array stored in a structure that I will write to a txt file.
My keyword is also in a txt file.
I think the function can be implemented by searching for spaces in my email body and comparing the characters between those spaces with my keyword to see if it is indeed in the text.

If you have any links or codes that could help me, I'd be grateful.

Thank you,

Configuration: Linux / Firefox 79.0

2 answers

  1. Phil_1857 Posted messages 1883 Registration date   Status Member Last intervention   169
     
    Hello Lakaiz,

    I am interested...

    In C, there is a function to search for a substring within a string,
    no need to look for spaces between words and compare characters:

    read keyword from mots_cles.txt
    read line from corps_mail.txt
    search keyword in line
    if not found: next line, etc ...
    2
    1. [Dal] Posted messages 6122 Registration date   Status Contributor Last intervention   1 108
       
      Yes, but if the keyword is "tart", maybe he doesn't want the program to react to "starter", for example.

      So a simple substring search function like
      strstr()
      is probably not desirable.
      1
  2. [Dal] Posted messages 6122 Registration date   Status Contributor Last intervention   1 108
     
    Hi Lakaiz,

    You should research the function
    strtok()
    , which allows, through successive calls to this function, to search for sequences of characters separated by delimiter characters, such as the space character.

    You will probably want to add punctuation to the delimiter characters.

    Dal
    1