title: How can I delete a string from a list using a function?
body: <p>I've tried and searched for this problem. I receive '3221225477' as a return value if I try to delete a string from the list. </p>
  
  <p>I've already tried using different approaches such as changing 'return value[];' in the const char* del(ListNodePtr *strPtr, value[]) function to 'return *value;' It would be much appreciated if you could tell me what should I change in my code. </p>
  
  <p>This is how I defined my structure. I don't know if this is really good.</p>
  
  <pre><code>        #include&lt;stdio.h&gt;
          #include&lt;stdlib.h&gt;
          #include&lt;string.h&gt;
  
          struct listnode
          {
              char data[100];
              listnode *nextPtr;
          };
              typedef struct listnode ListNode;
              typedef ListNode *ListNodePtr;
  </code></pre>
  
  <p>This is the insert function:</p>
  
  <pre><code>        void insert(ListNodePtr *strPtr, char value[])
          {
              ListNodePtr previousPtr, currentPtr, newPtr;
  
              newPtr=(listnode*)malloc(sizeof(listnode));
              strcpy(newPtr-&gt;data,value);
              newPtr-&gt;nextPtr=NULL;
  
              previousPtr=NULL;
              currentPtr=*strPtr;
              if(newPtr!=NULL)
              {
                         while(currentPtr!=NULL &amp;&amp; 
                                         strcmp(currentPtr-&gt;data,value)&lt;0)
                  {
                      previousPtr=currentPtr;
                      currentPtr=currentPtr-&gt;nextPtr;
                  }
  
                  if(previousPtr==NULL)
                  {
                      newPtr-&gt;nextPtr=*strPtr;
                      *strPtr=newPtr;
                  }
                  else
                  {
                      previousPtr-&gt;nextPtr=newPtr;
                      newPtr-&gt;nextPtr=currentPtr;
                  }
              }else printf("%s was not inserted. Insuffiecient memory!",value);
  
          }
  </code></pre>
  
  <p><strong>This is the 'delete' function:</strong></p>
  
  <pre><code>        const char *del(ListNodePtr *strPtr, char value[])
          {
              ListNodePtr previousPtr, currentPtr, tempPtr;
  
              if(strcmp(value, (*strPtr)-&gt;data)==0) /*if the 
                                 first node shall be deleted*/
              {
              /*delete node*/
              tempPtr=*strPtr;
              *strPtr=(*strPtr)-&gt;nextPtr;
              free(tempPtr);
              return *value;
              }
              else
              {
                  previousPtr=*strPtr;
                  currentPtr=(*strPtr)-&gt;nextPtr;
                  while(currentPtr!=NULL &amp;&amp; strcmp(value, 
                                            currentPtr-&gt;data)!=0)
                  {
                      previousPtr=currentPtr;
                      currentPtr=currentPtr-&gt;nextPtr;
  
                  }
  
                  if(currentPtr!=NULL)
                  {
                      tempPtr=currentPtr;
                       previousPtr- &gt;nextPtr=currentPtr-&gt;nextPtr;
                      free(tempPtr);
                      return *value;
                  }
              }
  
  
                  return '\0';//if the node is not found
  
          }
  </code></pre>
  
  <p>This is the main() function:</p>
  
  <pre><code>int main()
  {
      ListNodePtr startPtr;
      startPtr=NULL;
  
      int optiune;
      char nume[100];
  
      instructions();
      printf("? ");
      scanf("%d",&amp;optiune);
  
      while(optiune!=3)
      {
          switch(optiune)
          {
              case 1: 
                  printf("Enter name:");
                  fflush(stdin);
                  gets(nume);
                  insert(&amp;startPtr, nume);
                  printList(startPtr);
                  break;
  
              case 2:
                  fflush(stdin);
                  printf("Search by name to delete from list:");
                  gets(nume);
                  if(!Empty(startPtr))
                  {
                      if(del(&amp;startPtr, nume))
                      {
                          printf("%s was deleted!\n");
                          printList(startPtr);
                      }else printf("%s was not found!\n",nume);
  
                  }else
                      printf("List is empty!");
                  break;
  
              case 3:
                  break;
              default:
                  printf("No such option!\n\n");
                  instructions();
                  break;
          }
          printf("\n? ");
          scanf("%d",&amp;optiune);
      }
      printf("Execution stopped.\n" );
      return EXIT_SUCCESS;
  </code></pre>