Thread: Searching ........for help

  1. #1
    Patent Pending GSLR's Avatar
    Join Date
    Sep 2001
    Posts
    134

    Question Searching ........for help

    Hi
    I have a question on how i go about searching through a text file.

    actually i know there are a lot of functions that can be used but i dont know how to go about it.

    first off do i open a file and read it all into an array !
    This doesnt seem good as how do i know the size of the array that must be created as the file will get bigger all the time.

    What i do know is that each line in the file will not exceed 100 characters.
    But there can be as many lines as need be.

    I need some direction here, cause if i dont read the file into an array , how do i go about searching through the array or whatever??

    also I do know that i will only have to compare the first 30 characters of each line with an input string that the uset types in.

    Basically what i want to do is this:

    Enter name: John
    then the program goes and opens the text file (Here i get confused )
    it searches through the first 30 characters of each line and compares it to the users input.
    When it finds a match it outputs all 100 characters of that line.

    If anyone can give me direction here , thanx
    Also to keep it simple would be cool as im still learning this stuff.

    thanx
    And To All Those Opposed, WELL !!!
    >Deleted< " Looks like a serial no."

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Read the file one line at a time, like you were shown here .
    For each line read, use strncmp() to check the first 30 characters of the line against your user data (or you might want to use strstr() depending on your requirements).

    If you find a match, simply output the full line.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Patent Pending GSLR's Avatar
    Join Date
    Sep 2001
    Posts
    134
    Thanx
    will try and get back
    And To All Those Opposed, WELL !!!
    >Deleted< " Looks like a serial no."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Visual C++ 2005 linking and file sizes
    By Rune Hunter in forum C++ Programming
    Replies: 2
    Last Post: 11-12-2005, 10:41 PM
  4. Searching and matching strings: segmentation fault
    By Smola in forum C Programming
    Replies: 18
    Last Post: 07-11-2005, 12:25 AM