Reg: Searching for a word in a File

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mickey22
    New Member
    • Feb 2007
    • 105

    Reg: Searching for a word in a File

    How can I check for a particular word in a file?

    For eg

    //////a.txt

    Here is my first range
    A=10
    B=20
    Here is my second range
    A=30
    B=40

    I started reading each line and once I reach B=20 line, I wanted to go back to the first line “here is my first range” and look for the word first and then call some function.

    Similarly once I have read b=40, I wanted to read again line “here is my second range” and look for the word “second” and then call some function.

    Could anyone please help me with this?

    Thanks.
  • Savage
    Recognized Expert Top Contributor
    • Feb 2007
    • 1759

    #2
    Hi, here are some hints:


    1.Use ftell and fseek to return back on lines or just access it in array that u have
    populated.

    2.Use substring to get the vital word.

    3.Execute any function on that string.


    If u don't know how to use those functions go here

    and if u have question about any hint just post!!

    Savage

    Comment

    • mickey22
      New Member
      • Feb 2007
      • 105

      #3
      Thank you very much for the hints.I will try using the functions you have said.

      Comment

      • Savage
        Recognized Expert Top Contributor
        • Feb 2007
        • 1759

        #4
        Originally posted by mickey22
        Thank you very much for the hints.I will try using the functions you have said.
        U are welcome!!

        And if u have problems remember to post them here.


        Savage

        Comment

        • mickey22
          New Member
          • Feb 2007
          • 105

          #5
          Actually I have used the switch statemnet to solve this problem.I just set a count variable and used this count variable to access different cases in switch statement.

          Using switch statement made it bit easier to my application.I just wanted to let u know if somebody hase the same prob they can look for the solution.

          Thanks once again

          Comment

          • Savage
            Recognized Expert Top Contributor
            • Feb 2007
            • 1759

            #6
            Originally posted by mickey22
            Actually I have used the switch statemnet to solve this problem.I just set a count variable and used this count variable to access different cases in switch statement.

            Using switch statement made it bit easier to my application.I just wanted to let u know if somebody hase the same prob they can look for the solution.

            Thanks once again

            Great work!

            It's nice that u wish to help others.

            Keep it up!!

            Savage

            Comment

            Working...