Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching for strings

Status
Not open for further replies.

PlasmaZero

Programmer
Dec 6, 2002
13
US
I'm writing a prog in which a file is loaded with several hundred names into a listbox. I want to make a search function, i.e. user types a name or a partial name and the function loops through the listbox and sets the cursor on a match(if any). I have no idea how to implement this (especially for a partial match). Any suggestions/help would be appreciated.
Thanks
 

This little search function might doit:
Code:
#include <string.h>
#define _MAXSTRING_    100

bool Search( FILE *f, char *string )
{
	char *buff;
	buff   = new char[_MAXSTRING_];
	bool found = false;

	while( fgets( buff, _MAXSTRING_, f ) != NULL )
	{
		if( strstr( buff, string ))
		{
			found = true;
			break;
		}
	}

	delete buff;
	return found;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top