how to search in a file ,c++

Thread Starter

nada_fci_cu

Joined Oct 30, 2010
14
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
 

Thread Starter

nada_fci_cu

Joined Oct 30, 2010
14
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
 

nerdegutta

Joined Dec 15, 2009
2,689
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.
 

shteii01

Joined Feb 19, 2010
4,644
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.
 

Thread Starter

nada_fci_cu

Joined Oct 30, 2010
14
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 ?
 

nerdegutta

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

Is the text file organized like this?
Rich (BB code):
bookTitle, bookAuthor, bookSubject
Or like this?
Rich (BB code):
bookTitle
bookAuthor
bookSubject
Or like this?
Rich (BB code):
bookTitle, bookAuthor, bookSubject, bookTitle, bookAuthor, booSubject.... and so on
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.
 

nerdegutta

Joined Dec 15, 2009
2,689
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?
 

nerdegutta

Joined Dec 15, 2009
2,689
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?
 
Top