can anyone help me!? i have to create program to search word from text file, but i don't know how can i match word from input to text.. Can anybody help!!!??
ojung -5 Newbie Poster
Recommended Answers
Jump to PostFirst you have to extract a word from your text file.
Second compare it with the word you want to search.
true?-->found!
false?-->extract the next word from the file and compare again etc.
until the end of file is reached.
Jump to PostMy advice, do not use eof() it's counter productive. Instead do this.
while(getline(file, someString)){ //yourcode }
Chris
Jump to PostPlease use code tags.
Secondly, avoid goto statements, there are much better ways of achieving the same results. http://www.cprogramming.com/tutorial/goto.htmlSecondly there is no word[30] to word[299], they don't exsist so thats a very bad move to make. Also if the character …
Jump to Postcout<<"Enter word to search \n";
cin>>word;that should be
cin >> word;
, because word is a char, and word is a char array
while(dict.getline(text,300))
{
if(word[j]!=text[j])
{Likewise this should be
... if(string(text).find(word) != string::npos){ ...
, otherwise you are comparing the first …
All 15 Replies
ddanbe 2,724 Professional Procrastinator Featured Poster
ojung -5 Newbie Poster
ddanbe 2,724 Professional Procrastinator Featured Poster
mrnutty 761 Senior Poster
ojung -5 Newbie Poster
swyncoop 0 Newbie Poster
Freaky_Chris 299 Master Poster
iamthwee commented: Amen +17
ojung -5 Newbie Poster
Freaky_Chris 299 Master Poster
ojung -5 Newbie Poster
ddanbe 2,724 Professional Procrastinator Featured Poster
ojung -5 Newbie Poster
ojung -5 Newbie Poster
Salem commented: 10+ posts, still hasn't figured out code tags - a lost cause -5
dougy83 74 Posting Whiz in Training
onksssss 0 Newbie Poster
jonsca commented: Don't bump old threads +0
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.