DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Need help!!!search word from text file and display lines which match the word. (http://www.daniweb.com/forums/thread160794.html)

ojung Dec 4th, 2008 8:34 pm
Re: Need help!!!search word from text file and display lines which match the word.
 
I try to fix it,but i can't Please help me!!

ojung Dec 4th, 2008 8:34 pm
Need help!!!search word from text file and display lines which match the word.
 
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;
}

MosaicFuneral Dec 4th, 2008 8:58 pm
Re: Need help!!!search word from text file and display lines which match the word.
 
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.

ojung Dec 4th, 2008 9:04 pm
Re: Need help!!!search word from text file and display lines which match the word.
 
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


All times are GMT -4. The time now is 10:33 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC