|
| iMatix home page | << | < | > | >> |
SFLVersion 2.11 |
#include "sflstr.h"
char *
findstrinfile (
FILE *fp,
char *strtofind,
char *strretstr,
int *iLnNo)
Find's a string inside a text file and reads the line in and sets the file pointer to the beginning of that line. Assumes the line length to be <= 1024 bytes. Returns a pointer to head of the return buffer, and the file postion will be at the start of the found string. If the strretstr param is != NULL then strretstr will contain the line that the search string was found in. Submitted by Scott Beasley jscottb@infoave.com
{
char strline[1025];
int nfnd = 0;
long lfpos;
ASSERT (fp);
ASSERT (strtofind);
ASSERT (strretstr);
if (strretstr)
*strretstr = 0;
while (1)
{
lfpos = ftell (fp);
fgets (strline, 1024, fp);
trim (strline);
if (!*strline)
continue;
if (iLnNo)
(*iLnNo)++;
if (stricstr (strline, strtofind))
{
if (strretstr)
{
strcpy (strretstr, strline);
}
fseek (fp, lfpos, SEEK_SET);
nfnd = 1;
break;
}
if (feof (fp))
break;
}
if (strretstr)
return strretstr;
else
return (char *)nfnd;
}
| | << | < | > | >> |
|