i am not new to c++ and have been using it for quite a while now but there is this problem that i never solved and it goes like this: there is this dictionary text file and a sample of what it contains is like this:
*name - a noun or word used to identify //this is line 4
*id - abbreviation for identification // this is line 5
now, i'm writing a program that should work like this:
1. ask the user for a word to search in the dictionary text file
(for example, the user enters "name")
2. the program then stores the input to a variable and adds "*" to the value of the variable such that the final value of the variable is "*name"
3. then, look up the text file for the first occurrence of "*name"
4. get the line of the instance wherein the string "*name" first occurs (in our case, line 4)
5. gets the contents of that line and stores it to another variable (in our case, the content of the line is "*name - a noun or word used to identify")
6. edits the value of the variable and takes away the first character in the value of the variable (in our case, the initial value of the variable is "*name - a noun or word used to identify" and after taking away the first character ("*"), the final value of the variable becomes "name - a noun or word used to identify")
7. output the line (in our case, the program should output the value of the variable which is "name - a noun or word used to identify")
finally, to give you an idea on how the screen should look like...
Enter a word: name
Definition: name - a noun or word used to identify
generally i need a code for a text-file based dictionary...
and, it's not homework... it's some kind of a hobby thing for me... ;)
ok, here's a wider view of the problem:
i have this text file whose content is like:
*apple - a red fruit //line 1
*banana - a yellow fruit //line 2
*guava - a green fruit //line 3
*grapes - a violet fruit //line 4
then, i have a program which asks the user to enter a word.
then for example, the user enters "guava", instead of searching the text file for the word "guava", it searches the text file for "*guava". then the program gets the line where the word "*guava" is and outputs the whole line where "*guava" is; but it should take away the first character in the line so that the final output becomes "guava - a green fruit"....
Well the easiest thing would be putting all the data of the file into one single string
Then searching the string for '*'+fruit, and output all characters from the point where '*'+fruit was found, until you reach '\n', or until the string ends.
Both links i posted earlier should tell you how to do it