how to search in a file ,c++

Discussion in 'Programmer's Corner' started by nada_fci_cu, Dec 11, 2010.

  1. nada_fci_cu

    Thread Starter New Member

    Oct 30, 2010
    14
    0
    um working on a project in which um making something like a library system
    i wanna search about a book name in a file which contains all book names and when the user enters only one or 2 letters of the book name the program shows all books with entered letters then the user continue and the number of results decreases until he finds the wanted book (prog. language : C++)
    (i hope that someone understands me because i cant express well in English)
    can anyone help please
     
  2. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    How is this library file organized?

    What OS are you using?
     
  3. nada_fci_cu

    Thread Starter New Member

    Oct 30, 2010
    14
    0
    sorry what do u mean ?
    the book names are listed in a file (file.txt)
    if u mean operating system with OS the answer is windows.. vista
    if u mean another thing plz tell me
     
  4. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    Seems to me you are designing some kind of database-system. What information about a book are you going to register, and how are you going to index that information?

    Is it going to be lots of books or just >100?

    How is this textfile going to be organized?

    Lots of things to consider when you are designing this kind of system.
     
  5. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,383
    495
    Sounds like a sorting algorithm. I think most of us have done them while learning C.

    Google sorting algorithm, should be plenty of code floating around.
     
  6. nada_fci_cu

    Thread Starter New Member

    Oct 30, 2010
    14
    0
    nerdegutta=> 1.the information are book name,writer,subject
    and i wanna make the user search either by name or by writer or by subject
    2.no lots of books i will not make a full system it is part of the project
    3.about organizing the books as i said they r all written in atext file
    is this right or should we write them in an array?
    um still abeginner and i need an urgent help
    shteii01=> thanks for trying to help but please can u explain more ?
     
  7. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    How is the text file organized? Meaning how do you separate one book from the other?

    Is the text file organized like this?
    Code ( (Unknown Language)):
    1.  
    2. bookTitle, bookAuthor, bookSubject
    3.  
    Or like this?
    Code ( (Unknown Language)):
    1.  
    2. bookTitle
    3. bookAuthor
    4. bookSubject
    5.  
    Or like this?
    Code ( (Unknown Language)):
    1.  
    2. bookTitle, bookAuthor, bookSubject, bookTitle, bookAuthor, booSubject.... and so on
    3.  
    I think I would make the program read the text file into an array and let the array sort the file.

    The I guess it would be easy to search for titles, authors or subjects.
     
  8. nada_fci_cu

    Thread Starter New Member

    Oct 30, 2010
    14
    0
    like the first code u wrote
    bookTitle, bookAuthor, bookSubject
    bookTitle, bookAuthor, bookSubject
    .......
     
  9. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    OK, then you need to make a function that reads the file, line by line, putting the fields in an array. Separated with a comma-sign(,).

    When the function reaches the EOF-mark, it goes out of the loop, and into a sorting algorithm.

    You now have a sorted array of the bookLib.txt file.

    How is the GUI? One search-field?
     
  10. nada_fci_cu

    Thread Starter New Member

    Oct 30, 2010
    14
    0
    thanks alot, i understand
    about the GUI we will use the QT creator
    about the "One search-field" i dont know what do u mean ??
     
  11. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    Have you thought of how to present the sorted data?

    Is the screen/window divided in two, upper half containing the search field, and the lower showing a list of books that matches the search field?
     
  12. nada_fci_cu

    Thread Starter New Member

    Oct 30, 2010
    14
    0
    actually no,but it seems a good idea
    but how to make it ?
     
  13. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    What do you actually have so far, mister?
     
  14. nada_fci_cu

    Thread Starter New Member

    Oct 30, 2010
    14
    0
    as i said um still a beginner
    anyway thanks,mister
     
  15. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    You are welcome, mister :)

    Anytime :)
     
Loading...