[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.0

Searching for string in file

Asked by RJSoft in C++ Programming Language

Tags: string, file

Hello.

I have a routine to search a drive for files of certain type to see if they contain a string of text. Just like Windows Explorer has.

Except min is extremely slow.

What mine does is goes char by char through a file and loads a sizeable buffer reading from the file to a buffer. Then that buffer is examined by CStrings Find member for the search string.

The reason I have to make it increment one char at a time is because sometimes the sought after string may be only partialy picked up by the buffer being read into.

Example:
Say I was looking for string "abc";

My text file has string 12abc123

Now if I search with a buffer sized 4 chars (Buff) and start at beginning to end of file in a while read loop the first loop over the file data will miss the string

while(fread(Buff..))

1=Buff==12ab
2=Buff==c123

and the results is not found.

So instead I use fseek and do the loop over and over

while(1)
{
fseek(fptr,x,0);

while(fread(Buff...))
{
if(Same)....break;return;
}

x++;
}

This works but is slow. Because not only am I going through each file char by char but also I am repeating reading larger chunks. Buff is actually determined by a percentage of the current file size. So at least the while fread loop is sped up as much as possible.

I also considered just reading the whole file into 1 buffer which would speed things up drastically. BUT the user may have extremley large files. I do not know what CString can handle as I will have to load the Buffer into a CString.

Also that does not seem like good form. Because who knows about future file sizes.

I am considering some sort of value system where I can assign values to the first loop of large buffer size accourding to how "CLOSE" each buffer cam to matching the search string.

Say if one buffer had 1 char another buffer had 2 chars (In same order) then it would get a 2 and so on...

Then the buffer with the largest similar count would be re-examined by extending it's length in order to read the whole possible text from the file. If it does exist then.

Any ideals would be apreciated. Sorry about the lack of points.
RJ

Here is the code.

int XXXXXX::StringFound(char *SearchSt, char *FileName)
{
CString CBuff;
CString Search=SearchSt;
int found =0;
::GetShortPathName(FileName,FileName,MYMAXPATH-1);
//
//
////////////////Get the file size
long FileSize=0;
long x=0;
struct _finddata_t ptffblk;
long fhandle = _findfirst(FileName,&ptffblk);
if(fhandle==-1)
{
MessageBox("Failed to _findfirst",FileName);
return 0;
}
else _findclose(fhandle);
FileSize=ptffblk.size;
/////////////////////////////////
//
long Size=0;
long Ms=MYMAXPATH;//arround 1,000
if(FileSize<Ms)Size=FileSize;
else Size=Ms;
//
char *Buff= new char[Size];
//
FILE *fptr=NULL;
fptr=fopen(FileName,"rb");

if(fptr!=NULL)
{
      while(1)
      {
      fseek(fptr,x,0);// start from beginning and offset x amount

      while(fread(Buff,Size,1,fptr))
      {
            //MessageBox(Buff);
            CBuff=Buff;
            CBuff.MakeLower();
            Search.MakeLower();

            if(CBuff.Find(Search)!=-1){found=1;break;}

      }//endwhileread
      

      x++;

      if(Size==FileSize)break;

      if(x>=FileSize || found)break;
      }//endwhile

      fclose(fptr);
      delete[] Buff;

}//endifnotnull
return found;
}//endfunc

[+][-]01/26/05 08:45 AM, ID: 13143843Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/26/05 08:46 AM, ID: 13143855Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/26/05 08:50 AM, ID: 13143920Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/26/05 08:51 AM, ID: 13143943Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/26/05 08:52 AM, ID: 13143954Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/26/05 08:53 AM, ID: 13143962Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/26/05 09:09 AM, ID: 13144145Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/26/05 09:13 AM, ID: 13144194Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/26/05 10:29 AM, ID: 13145013Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/26/05 10:31 AM, ID: 13145036Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/26/05 10:38 AM, ID: 13145100Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/26/05 10:39 AM, ID: 13145111Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/26/05 11:36 AM, ID: 13145652Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/26/05 11:44 AM, ID: 13145736Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/26/05 01:55 PM, ID: 13147196Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/27/05 08:28 AM, ID: 13153932Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/27/05 08:33 AM, ID: 13153983Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/27/05 08:34 AM, ID: 13154000Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/27/05 08:46 AM, ID: 13154172Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/27/05 08:51 AM, ID: 13154246Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/27/05 09:25 AM, ID: 13154675Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/27/05 09:28 AM, ID: 13154707Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/27/05 09:30 AM, ID: 13154729Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/27/05 09:31 AM, ID: 13154749Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/27/05 10:36 AM, ID: 13155376Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/27/05 10:44 AM, ID: 13155469Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/27/05 11:27 AM, ID: 13155975Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: C++ Programming Language
Tags: string, file
Sign Up Now!
Solution Provided By: Axter
Participating Experts: 5
Solution Grade: A
 
[+][-]01/27/05 11:30 AM, ID: 13156006Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/27/05 11:49 AM, ID: 13156241Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/27/05 12:22 PM, ID: 13156610Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/27/05 01:24 PM, ID: 13157305Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89