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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String slicing

Status
Not open for further replies.

chigley

Programmer
Sep 30, 2002
104
0
0
GB
Hi,

I have an array of structs, comprising the name of an application and the path

struct{
char name[50];
char path[1024];
}

I am trying to write a function to search this and build a sub set based on the search string.

Eg, If the search string is "Fi"

Then it would match from the left hand side only, based on the first two characters

So matching entries would be

Firefox.exe
Findfast.exe

for example

My biggest hurdle is my abysmal knowledge of string slicing functions and string comparison functions in C, and my googling efforts have been confusing at best.

Here is the skeleton of the function

Code:
void filterEnumeratedPrograms(char * searchString)
{
	int i=0;
	int length=0;
	length = strlen(searchString);
	printf("Search string %s is %d characters long \n", searchString,length);
	
	for (i=0;i<lNumPrograms;i++)
	{
		//comparison goes here
	}
	
}

can anyone post some code to steer me in the right direction?

Charlie Benger-Stevenson
Hart Hill IT Ltd
 
strncmp() should do the trick.


--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top