![]() |
| ||
| searching for keywords in multiple text files Hello, I'm working on a code for my project at college. The goal of the project is to find and extract keywords, and the sentences, which contain these keywords from many text files, which I have already downloaded from Internet using another code. These text files are actually source codes of different websites and my program needs to search for certain keywords, which I store in another text file called "keywords.txt". It should also search for all keywords in all text files. So I tried to do it using some while-loops. Although I got some results, my code only searchs for the first keywords, that lies on the top line of "keywords.txt" and other keywords are unfortunately not searched. I can search only this one keywords in all text files; I get the places and names of these text files from a file called "addresses.txt". Could you please look at my code and tell me what could be wrong about it and what should I do for my code to search for all keywords in "keywords.txt"? I would also appreciate some hints about how I could manage this process using vector class, since using arrays is not really appropriate, because I have to change the size of arrays everytime when I add new addresses or keywords, manually. I have some knowledge of vectors, but I couldn't implement it into my code. Here is the code I have written: -------------------------------------------------------------------------------- #include <iostream>-------------------------------------------------------------------------------- Thanks for your help :) |
| ||
| Re: searching for keywords in multiple text files I'm not sure if this will work, but try while(keywords>>keyword != NULL) |
| ||
| Re: searching for keywords in multiple text files Thanks for the reply, but it doesn't work.. |
| ||
| Re: searching for keywords in multiple text files > while(addresses>>link>>name) Having got to the end of the addresses file once, where do you think you'll start off from with the second word from the keywords file? Even for a short program, your indentation is mis-leading and needs work. |
| ||
| Re: searching for keywords in multiple text files Quote:
|
| ||
| Re: searching for keywords in multiple text files As for the actual problem, I would go with a simpler method. Simply push all the keywords into a vector of strings, then load in the file to check against (a txt file) into another vector of strings. Then filter out the keywords manually, or get a little more elegant with a function such as SetIntersection() to find the similarities between the two, pushed into another vector. You can then use the resultant vector to do whatever parsing you wish (add the url info, etc) This will cut your code down by about 70%, and will get you brownie points with your teacher =) |
| ||
| Re: searching for keywords in multiple text files Quote:
|
| ||
| Re: searching for keywords in multiple text files Quote:
ifstream inFile; Something like that should do the trick for filling a vector from a file. It might not be syntactically correct, since I didn't try to compile it. |
| ||
| Re: searching for keywords in multiple text files Quote:
Simplified: ifstream file("name"); |
| ||
| Re: searching for keywords in multiple text files thanks, everyone. I have solved the problem =) It was a basic loop error.. |
| All times are GMT -4. The time now is 6:41 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC