Programming C - searching for same words from text file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dafrancesko
    New Member
    • Jan 2014
    • 2

    Programming C - searching for same words from text file

    Hi,

    I would be glad if you would help me with this program:

    Task:

    User will enter 4-7 letters (for example 'ADFG').

    I have detached text file which contains about several thousand of words

    (for example:

    BDF
    BGFK
    JKLICV
    NGJKL
    POIUEVBN

    etc.)

    -words are written in list

    I want to make program, which find words from this text file, which are same letters which user entered

    (In this case, when I entered ADFG it will find and display BDF, BGFK, NGJKL).
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    I would start by writing a function:

    Code:
    int Test(char token, char* str);
    This function would take a char token and a string str. The function returns a non-zero value (TRUE) if the token is in the str and 0 (FALSE) otherwise.

    Then in main() write loop that calls this function for every character in ADFG using a word from the text file as str.

    Since ADFG is a string, you can use strlen to determine how many time to call this function. You can also use strlen inside the function to determine how many characters are in the string to be searched.

    Embed this loop inside a larger loop that reads the text file word by word.

    And there it is...

    BTW: I can't just write the code for you but I can help with code you write. Keep me posted.

    Comment

    • dafrancesko
      New Member
      • Jan 2014
      • 2

      #3
      Here is my code <weaknessforcats>
      When I run it, there will appear infinite (null)(null)(nu ll)...
      Last edited by weaknessforcats; Jan 22 '14, 02:59 PM. Reason: spoonfeeding

      Comment

      Working...