title: function to check if string exists in C linked list
body: <p>I am writing a program for class and my instructor asked us to check if a name already exists in our list before we add it. The code that I have written to do this does not seem to be working properly.</p>
  
  <pre><code>    void doAdd (waitListPtr hd)
  {
   /* get group size from input */
  int size = getPosInt();
  if (size &lt; 1)
  {
  printf ("Error: Add command requires an integer value of at least 1\n");
  printf ("Add command is of form: a &lt;size&gt; &lt;name&gt;\n");
  printf ("  where: &lt;size&gt; is the size of the group making the reservation\n");
  printf ("         &lt;name&gt; is the name of the group making the reservation\n");
  return;
  }
  
  /* get group name from input */
  char *name = getName();
   if (NULL == name)
  {
  printf ("Error: Add command requires a name to be given\n");
  printf ("Add command is of form: a &lt;size&gt; &lt;name&gt;\n");
  printf ("  where: &lt;size&gt; is the size of the group making the reservation\n");
  printf ("         &lt;name&gt; is the name of the group making the reservation\n");
  return;
  }
      if(doesNameExist(hd, name) == TRUE){
          printf("\nERROR: Name already on list");
      }else{
      printf ("Adding group \"%s\" of size %d\n", name, size);
      addToList(&amp;hd, size, name);
      hd-&gt;groupStatus = PRESENT;
      }
  }
  </code></pre>
  
  <p>It never gives an error and always just adds the name to the list.</p>
  
  <p>Here is the doesNameExist function:</p>
  
  <pre><code>int doesNameExist(waitListPtr hd, char* name){
  
  waitListPtr ptr = hd;
  
  while(ptr != NULL){
      if(strcmp(ptr-&gt;groupName, name)== 0){
          return TRUE;
      }
      else{
          ptr=ptr-&gt;next;
      }
  }
  return FALSE;
  </code></pre>
  
  <p>}</p>
  
  <p>here is the declaration of my linked list structure</p>
  
  <pre><code>typedef struct waitListStruct
  {
  char      groupName[30];
  int       groupSize;
  int       groupStatus;
  struct    waitListStruct*  next;
  } waitList;
  
  typedef waitList* waitListPtr;
  </code></pre>
  
  <p>here is the function to add a new node to the list</p>
  
  <pre><code>void addToList(waitListPtr* hd, int size, char* name){
  
  waitListPtr ptr = (waitListPtr) malloc (sizeof(waitList));
  
  strcpy(ptr-&gt;groupName, name);
  
  ptr-&gt;groupSize = size;
  
  ptr-&gt;next = *hd;
  
  *hd = ptr;
  
  }
  </code></pre>
  
  <p>this is the part in main where the function is called</p>
  
  <pre><code>int main (int argc, char **argv)
  {
  
   waitListPtr head = NULL;
  
  
   while ((ch = getNextNWSChar ()) != EOF)
   {
  if('a' == ch)
    {
     doAdd(head);
   }
   }
   }
  </code></pre>
  
  <p>Can anyone tell me what I've done wrong?</p>