Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

String slicing

String slicing

String slicing


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

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


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


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

RE: String slicing

strncmp() should do the trick.

If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close