I have a program and one of the things i need to do is search through the list of movies and find all the ones that have a certain word in it. Any ideas on how i could do this? Thank you.
I have a program and one of the things i need to do is search through the list of movies and find all the ones that have a certain word in it. Any ideas on how i could do this? Thank you.
http://msdn.microsoft.com/library/de...nipulation.asp
There might be something in there.
that's a c library. don't use it.Originally Posted by bumfluff
OP, when you say "list of movies", what do you mean? a file with a bunch of names? a directory of mpegs?
post more info on the problem and tell us what you've tried so far.
BTW "Question" is just about the worst thread title ever. if you learn how to ask smart questions you're more likely to get an answer.
"I saw a sign that said 'Drink Canada Dry', so I started"
-- Brendan Behan
Free Compiler: Visual C++ 2005 Express
If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?
The list of movies is in a .txt file. For example :
Meet Joe Black
Meet the Parents
Someting about Mary
Gone in 60 seconds
Father of the Bride
fstream in(" \\insertfile name here.
string s;
while(getline(in,s,'\n')){
if(s.find("seconds")!=string::npos)
cout<<s;
}
but remember one thing Joe is not the same as joe.Code:
Last edited by qqqqxxxx; 03-24-2006 at 01:14 AM.
Second to "Urgent Question Please Help", eh?Originally Posted by ChaosEngine
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers
Please give up at life now.Originally Posted by qqqqxxxx
well, here's one way you can do it... note that it's inefficient:and don't even try to take this as your own work... you would most certainly fail the assignment if you handed this inCode:#include <iostream> #include <fstream> #include <string> std::string capitalize(std::string&in); int main() { std::string word; std::string search; int line=1; char ch; struct link; struct link { int data; link*next; } *curr,*next,*head=new link; curr=head; curr->data=-1; curr->next=0; std::fstream file("test.dat",std::ios::in); std::cout<<"Enter your seach word: "; getline(std::cin,search,'\n'); while(file>>word) { file.get(ch); if(capitalize(search)==capitalize(word)) { curr->data=line; next=new link; curr->next=next; curr=next; curr->data=-1; curr->next=0; } line=(ch=='\n'?line+1:line); } curr=head; std::cout<<"Matches were found on line(s): "; while(curr->next) { std::cout<<curr->data<<", "; curr=curr->next; } std::cout<<std::endl; return 0; } std::string capitalize(std::string&in) { for(unsigned int i=0;i<in.length();i++) { in.at(i)=toupper(in.at(i)); } return in; }
you'd best ignore the curr/head/data/link stuff and figure out your own way to record the results - I just put that in there to ensure you didn't get copyable code... sure, it works, but it's only half a program... (don't take that wrong, the searching algo is complete, it's the linked list that's not finished.)
searching algorithms can get fairly complex, as touched upon in this wiki article, but on small amounts of data like this, you probably aren't looking for a very good algorithm.
Last edited by major_small; 03-24-2006 at 10:01 AM.
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT