Find the answer to your Linux question:
Results 1 to 4 of 4
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2005
    Posts
    2

    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.
    thanks.

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

    or..

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

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

  4. #4
    Linux Guru kkubasik's Avatar
    Join Date
    Mar 2004
    Location
    Lat: 39:03:51N Lon: 77:14:37W
    Posts
    2,396
    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...

    http://cprogramming.com/discussionar...searching.html

    http://www.cprogramming.com/tutorial.../sortcomp.html
    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
  •