On 28 Feb 2004 12:22:33 -0800,
(spike) wrote:
>Im writing a program to search for a string in a binary file.
>And it works. The problem is: It is sooo slow! how can i make it faster?
>It takes 27 seconds just to search a 5 meg file.
>I guess it has something to do with the strequal() function...
>
>Btw, thanks to all of you who answered last time!
>
>code:
>-------------------------------------------------------------------------
>#include <stdio.h>
>#define MAXLEN 50
>#define FALSE 0
>#define TRUE !FALSE
>#define STRSIZE 4
>
>int strequal(char sText[],char sBuff[])
>{
> int iRetval = TRUE;
> int i;
> for(i=0;i<STRSIZE;i++)
> {
> if(sText[i] == sBuff[i])
> {
> iRetval = iRetval && TRUE;
I don't know if this contributes to your timing problem but this can
never change the value of iRetval and is effectively a no-op.
> }
> else
> {
> iRetval = iRetval && FALSE;
Similarly, this can only and will always set iRetval to FALSE.
Furthermore, once iRetval is FALSE, it can never become TRUE so there
is no point in continuing the loop.
> }
> }
> return iRetval;
>}
>
snip
<<Remove the del for email>>