display 20 characters on each side of a strstr result
Posted on 2003-03-19
i am doing a little app that requests a search term, opens a file, loops through the file looking for the search and displays each occurence of the term on screen.
after i find the term using:
inFile.getline(buf, 299, '\n');
char * pch;
pch = strstr (buf,searchTerm);
i want to set the pointer 10 characters back in the file and then extend the length of the substring by the searchTerm and another 10 characters e.g.
nnnnnnnnnn searchTerm nnnnnnnnnn
so it is centred and we can see the text either side of the search term.
another problem i forsee is if the search term is found less than 10 characters from the start or end of the string in 'buf'