title: Field of a structure changing randomly and i cant find the issue
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;ctype.h&gt;
  #include &lt;stdbool.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  #define MAX_LINE  80
  
  int historyLength=10;
  int currentNumberOfHistoryElements=0;
  int currentCommandNumber=1;
  int notDone=1;
  size_t n=MAX_LINE;
  
  struct pastCommand
  {
  
      char *command;
      char *commandslist[10];
      int commandlistLength;
  };
  
  void addNewHistory(struct pastCommand *newHistory,struct pastCommand *historyList[])
  {
      char *look = newHistory-&gt;command;
      printf("HEREsad %s\n",look );
      if(currentNumberOfHistoryElements&lt;historyLength)
      {
          for(int i=0; i&lt;historyLength; i++)
          {
              if(historyList[i]==NULL)
              {
                  historyList[i]=newHistory;
                  currentNumberOfHistoryElements++;
                  break;
              }
          }
      }
      else
      {
          for(int i=0; i&lt;historyLength-1; i++)
          {
              historyList[i+1]=historyList[i];
          }
  
          historyList[0]=newHistory;
      }
  }
  
  void printHelp()
  {
      printf("List of Commands:\n Verbose[on|off]: shows info as commands called \n help: what you are looking at right now\n history: the past 10 commands you have entered\n quit: quit the program\n");
  }
  
  void printHistoryElement(struct pastCommand *currentHistory, int number)
  {
      if(currentHistory==NULL)
      {
  
  
      }
      else
      {
          int myLength=currentHistory-&gt;commandlistLength;
          char *myCommand=currentHistory-&gt;command;
          printf("LOOKIE %s\n",myCommand);
  
          printf("Commands #%d: %s\n",number, myCommand);
          for(int i=0; i&lt;myLength; i++)
          {
  
              printf("arg[%d] :%s\n",i,currentHistory-&gt;commandslist[i]);
          }
          printf("\n");
      }
  }
  
  void printHistory(struct pastCommand *allHistories[],int length)
  {
      for(int i=0; i&lt;length; i++)
      {
          printHistoryElement(allHistories[i],i);
      }
  }
  
  void freeHistoryList(struct pastCommand *allHistories[])
  {
      for(int i=0; i&lt; historyLength; i++)
      {
          if(allHistories[i]!=NULL)
          {
              free(allHistories[i]);
          }
      }
  }
  
  void runProgram()
  {
      struct pastCommand *allCommands[historyLength];
      for(int i=0; i&lt;10; i++)
      {
          allCommands[i]=NULL;
      }
      char* buf = (char*) malloc(sizeof(char) * MAX_LINE);
  
      while(notDone)
      {
          printf("mish[%d]&gt; ",currentCommandNumber);
  
          int result=getline(&amp;buf, &amp;n, stdin);
          if(result==-1)
          {
              printf("\n");
              exit(EXIT_FAILURE);
          }
          else
          {
              strtok(buf,"\n");
              if(strcmp(buf,"help")==0)
              {
                  printHelp();
                  struct pastCommand *current=malloc(sizeof(struct pastCommand));
                  current-&gt;command=malloc(sizeof(buf));
  
                  current-&gt;command=buf;
                  printf("%s\n",current-&gt;command );
                  current-&gt;commandlistLength=0;
                  addNewHistory(current,allCommands);
                  printf("HIT IT\n");
              }
              else if(strcmp(buf,"quit")==0)
              {
                  free(buf);
                  freeHistoryList(allCommands);
                  exit(EXIT_SUCCESS);
              }
              else if(strcmp(buf,"history")==0)
              {
                  printHistory(allCommands,currentNumberOfHistoryElements);
              }
          }
  
          currentCommandNumber++;
      }
  }
  
  int mish_command_name(int argc, char *argv[])
  {
      return 0;
  }
  
  int main(int argc, char *argv[])
  {
      runProgram();
      return 0;
  }
  </code></pre>
  
  <p>Overall the issue is I'm keeping a history of commands that are to be run. When I type <code>help</code>, it works fine and I see <code>help</code> is added to the history list with the command name <code>help</code>. However, when I type <code>history</code> to show it, the command name which is being printed changes to <code>history</code> which is really weird.</p>
  
  <p>I tried to debug as you can see from the code and I have no idea how the field variable for the structure is changing from <code>help</code> to <code>history</code>. If I type <code>help</code> like 5 times, then type <code>history</code>, all the command names have the name <code>history</code>.</p>
  
  <p>Some insight would be incredibly helpful. </p>