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.
Printable View
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.Quote:
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. :p if you learn how to ask smart questions you're more likely to get an answer.
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:
Second to "Urgent Question Please Help", eh?Quote:
Originally Posted by ChaosEngine
Please give up at life now.Quote:
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 in :DCode:#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.