Searching for a list specific words in a string

This is a discussion on Searching for a list specific words in a string within the C Programming forums, part of the General Programming Boards category; Hi, I have a basic problem and am unsure of how to approach it best. I have a file which ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    108

    Question Searching for a list of specific words in a string

    Hi,

    I have a basic problem and am unsure of how to approach it best.

    I have a file which has a header of :
    "hello";"my";"name";"is";"michael"
    I have read this file and saved it to a string called readfile.

    the second line also contains this data but the problem is that these words wont always appear in the same order so i need to search the first line (which is always in the right order) and assign tokens to each word.

    Then i want to search the second line for occurances of the word "hello" and give it the index of 1 as well.

    thus i can hypothetically construct a line of 1;2;3;4;5.

    i wanted to know that strtok seems to be the best way of doing it
    but how do i store the first line so that future lines in the file can use its index.

    all help will be appreciated
    Last edited by shoobsie; 04-26-2006 at 09:50 AM.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    108
    Hi thanks for your reply.

    I decided on using strtok and comparing the input to a table of predefined values.

    thus i will be able to get the position in which they occur.

    I might need a bit of help for the next part so i will post it in a few hours.

    thanks

  4. #4
    Registered User
    Join Date
    Feb 2006
    Location
    Great India
    Posts
    24
    Can you please post your original question ? I mean the same you are trying . It sounds interesting to work out. Please type out the original question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 05:30 PM
  2. compiler build error
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2003, 10:16 AM
  3. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 06:46 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21