Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    search a specify line

    Hi, i have a txt file and im writing a program(on c++) to read that file
    ang go to a specify line.
    how can i do that????
    i had a lot of problems.

  2. #2
    Linux Engineer
    Join Date
    Apr 2005
    Buenos Aires, Argentina
    grep whatever filename


    cat filename | grep whatever
    "All the drugs in this world won\'t save you from yourself"

  3. #3
    Linux Engineer
    Join Date
    Mar 2005
    He wanted to do it in C++, he want the sourcecode.

  4. $spacer_open
  5. #4
    Linux Guru kkubasik's Avatar
    Join Date
    Mar 2004
    Lat: 39:03:51N Lon: 77:14:37W
    Searching and Sorting is an entire subset of computer science theory, and can be a bit complicated, Assuming you read each line as a string, then create an array of strings, you can perform some basic brute force searches using a simple loop and crude checking function (the exact syntax really depends how OO you go...) I'm assuming the file probably wont exceed the hundreds of lines, in which case, you really won't have serious performance issues (assuming you handle your memory well). Speed will become an issue in arrays exceeding 1000 elements or with more complex condition checkers. In that case, you will probably need to sort the array, so a binary search or the like can be performed.

    Here are a few decent starter tuts that should give you a more in depth idea of where I am taking this...
    Avoid the Gates of Hell. Use Linux
    A Penny for your Thoughts

    Formerly Known as qub333

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts