title: inserting string in stack using linked list
body: <p>i am confused with the code below. why does the input overwrite the elements in the stack.</p>
  
  <p>for example i enter "abc" first
  then the stack will be "123"
  but when i enter another string, let's say "234"
  the stack will be "234" "234"</p>
  
  <p>but when i used int data type instead of char for my input, there's no error. </p>
  
  <p>thanks!</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  struct node{
      char* info;
      struct node *ptr;
  }*top,*top1,*temp;
  
  int count = 0;
  
  /* Push data into stack */
  void pushy(char* data){
      if (top == NULL)
      {
          top =(struct node *)malloc(1*sizeof(struct node));
          top-&gt;ptr = NULL;
          strcpy(top-&gt;info, data);
      }
      else
      {
          temp =(struct node *)malloc(1*sizeof(struct node));
          temp-&gt;ptr = top;
          strcpy(temp-&gt;info, data);
          top = temp;
      }
      count++;
   }
  
  /* Display stack elements */
  void display(){
      top1 = top;
  
      if (top1 == NULL)
      {
          printf("Stack is empty");
          return;
      }
  
      while (top1 != NULL)
      {
          printf("%s ", top1-&gt;info);
          top1 = top1-&gt;ptr;
      }
   }
  
  /* Pop Operation on stack */
  void pop(){
      top1 = top;
  
      if (top1 == NULL)
      {
          printf("\n Error : Trying to pop from empty stack");
          return;
      }
      else
          top1 = top1-&gt;ptr;
      printf("\n Popped value : %s", top-&gt;info);
      free(top);
      top = top1;
      count--;
  }
  
  /* Return top element */
  char* topelement(){
      return(top-&gt;info);
  }
  
  int main()
  {
      int ch=0;
  
  
      printf("\n 1 - Push");
      printf("\n 2 - Pop");
      printf("\n 3 - Top");
      printf("\n 4 - Display");
      printf("\n 5 - Exit");
  
      top = NULL;
  
      while (1)
      {
          char no[10]={NULL};
          char* e;
  
          printf("\n Enter choice : ");
          scanf("%d", &amp;ch);
  
          if(ch==1){
              printf("Enter data : ");
              scanf("\n\n%s", &amp;no);
              pushy(no);
          }
          else if(ch==2){
              pop();
          }
          else if(ch==3){
              if (top == NULL)
                  printf("No elements in stack");
              else
              {
                  e = topelement();
                  printf("\n Top element : %d", e);
              }
          }
          else if(ch==4)
              display();            
          else if(ch==5)
              exit(0);
          else
               printf("Invalid");
     }
  }  
  </code></pre>