in the following function
If the line has at least two instances of the search string starting at or after the user-supplied interger offset, dump the part of the line between but NOT including the first two instances to the output file along with a '\n'.
Code:
void FileSearch(char *filename, char *OutFile, char *SearchString, int StartSrch)
{
char *ptr1,*ptr2,Line[MAXLEN];
FILE *fpIn, *fpOut;
int Len;
fpIn = Fopen (filename, "r");
fpOut = Fopen (OutFile, "w");
Len = strlen(SearchString);
while (fgets(Line,MAXLEN, fpIn) != NULL)
{
ptr1 = strstr(Line + StartSrch, SearchString);
if(ptr1)
{
ptr2 = strstr(ptr1 + Len,SearchString);
if(ptr2)
{
*ptr2 = '\0'';
ptr1 += Len;
}
}
else ptr1 = Line;
fputs(ptr1, fpOut);
}
Fclose(fpIn);
Fclose(fpOut);
}
If the fputs prints up to the '\0' and I write *ptr2 = '\0'
it continues printing the next line on the same line.
also I have a “wrapper.h”
for the Fopen and Fclose cases.