I'm trying to search a string array of names and return an integer to the main depending on if the search was successful or not. for example if the user entered name didn't exist it would return -1 and I can tell the user the name is not listed, but if the user enters a name that is listed it will return the postion of the string in the array. I'm pretty sure I need to use strcmp and maybe strcpy, but i've had a hard time understanding those completely in the context of what I'm trying to do with this program. Here is my code, Maybe you seasoned vets could help a rookie like myself out.


#define MAX_NAMES 5
void initialize(char names[MAX_NAMES][MAX_NAMELENGTH]);
int search(char names[MAX_NAMES][MAX_NAMELENGTH],int i);
int main()

    char names[MAX_NAMES][MAX_NAMELENGTH];
    int i;
    return 0;

void initialize(char names[MAX_NAMES][MAX_NAMELENGTH])
     int i,Number_entrys;

     printf("How many names would you like to enter to the list?\n");

                   printf("Please choose a smaller entry\n");
      for (i=0; i<Number_entrys;i++){



int search(char names[MAX_NAMES][MAX_NAMELENGTH],int i)
    char new_name[MAX_NAMES][MAX_NAMELENGTH];
    printf("Now enter a name in which you would like to search the list for");

strstr() does exactly what you want, returning a pointer to the first char of the target string it finds. If the target string isn't found, strstr() returns NULL.

Wasn't that easy? ;)

if(strstr(string1, targetString)) {
   //code to handle a target string that was found
}else {
   //code to handle where a target string was not found
This article has been dead for over six months. Start a new discussion instead.