Need help!!!search word from text file and display lines which match the word.

Reply

Join Date: Nov 2008
Posts: 10
Reputation: ojung has a little shameless behaviour in the past 
Solved Threads: 0
ojung ojung is offline Offline
Newbie Poster

Re: Need help!!!search word from text file and display lines which match the word.

 
0
  #1
Dec 4th, 2008
I try to fix it,but i can't Please help me!!
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 10
Reputation: ojung has a little shameless behaviour in the past 
Solved Threads: 0
ojung ojung is offline Offline
Newbie Poster

Need help!!!search word from text file and display lines which match the word.

 
0
  #2
Dec 4th, 2008
Hi,I am Really new in C++. I'm trying to write a program which search word from text file and display matched word whole lines. Can any body help me out please?


#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{ int i;

char word[30];
char text[50];
fstream dict("bufferfile.txt",ios::in);

if (!dict.is_open())
{
cout << "Unable to open file";
system("pause");
exit(1);
}
cout<<"Enter word to search \n";
cin>>word;

loop:
i=0;
while(dict.getline(text,50))
{
while((word[i]!='\0')&&(text[i]!='\n'))
{ if(word[i] != text[i])
{
goto loop;}
else

cout<<text<<endl;


}
} ++i;
system("pause");
return 0;
}
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 922
Reputation: MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice 
Solved Threads: 92
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is offline Offline
Posting Shark

Re: Need help!!!search word from text file and display lines which match the word.

 
0
  #3
Dec 4th, 2008
A list of things to do:
Use code tags, realize you're programming in C++ not BASIC avoid goto , avoid system() whenever possible(it's slow, often unportable, and insecure in some cases), and reformat your code because someplaces look like errors but I can't tell.
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 10
Reputation: ojung has a little shameless behaviour in the past 
Solved Threads: 0
ojung ojung is offline Offline
Newbie Poster

Re: Need help!!!search word from text file and display lines which match the word.

 
0
  #4
Dec 4th, 2008
Yes it some Error occured but i don't know hoe to deal with it.
If you know please help me,,thank you so much
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC