0

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;
}

Edited by pritaeas: Fixed formatting

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by ojung
0

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.