searching for words in a file
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: searching for words in a file

  1. #1
    Join Date
    Mar 2012
    Posts
    1

    Post searching for words in a file

    i am new to visual c++ and i am learning oop ,i want ideas or how i can go about this small project i want to create i hope it will help me,i want to write a Class to search the file for a given pattern (eg, content) using visual c++
    i want to put a button called search and i want to put an editbox1 where i can enter the path of the where the file is located eg "c:\\folder\\file1_.txt",then another editbox2 where i can enter words i want to search more like a the find button in word2007,i want it to work in such a way that when i enter the path where the file is located and click open the file should open and when i enter the word and click search it should show the string or word....i need ideas on how i can do this or how to do it your response will be highly appreciated

  2. #2
    Join Date
    Apr 1999
    Posts
    27,429

    Re: searching for words in a file

    Quote Originally Posted by quantumlaws View Post
    i am new to visual c++ and i am learning oop ,i want ideas or how i can go about this small project i want to create i hope it will help me,i want to write a Class to search the file for a given pattern (eg, content) using visual c++
    i want to put a button called search and i want to put an editbox1 where i can enter the path of the where the file is located eg "c:\\folder\\file1_.txt",then another editbox2 where i can enter words i want to search more like a the find button in word2007,i want it to work in such a way that when i enter the path where the file is located and click open the file should open and when i enter the word and click search it should show the string or word....i need ideas on how i can do this or how to do it your response will be highly appreciated
    I would not concentrate on buttons, edit boxes, etc.

    You should be concentrating on the logic -- given strings to find and a path to a file, return the matches. All the fancy GUI components mean nothing if you can't actually search a file for strings.

    Assuming you're using MFC:
    Code:
    void SearchInFile(const CString& strToSearch, const CString& fileToSearch)
    {
       ////....
    }
    Assuming you're not using MFC:
    Code:
    void SearchInFile(const std::string strToSearch, std::string& fileToSearch)
    {
       ////....
    }
    
    int main()
    {
        SearchInFile("abc123", "myfile.txt");
    }
    It is the stuff in the middle of SearchInFile, regardless of what your GUI (or even if you have no GUI) that is important. There is no need for editboxes or buttons to write that code that's missing.

    Once you have that coded, then and only then should you think about the interface.

    Regards,

    Paul McKenzie

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center