So I wrote some code to implement the shell (Linux, GCC, C language) and it all works but from some reason the code crashes when I added the history option:
It really doesn't (the other code) so I'll put here only what you need.

The problem is when I type `quit` after one old command that need to be saved in the history and when I type quit it just crushes with segmentation fault (core dumped).

The history is saved in a structure of a linked list, string of command and the node for the next node, also I saved the head in the main. The point is that I want to save only 15 last commands, and I don't care about the others, so every time I want to print the list I just moved on the first 15 nodes in the loop.

When I debugged with GDB I saw that the line the code crashes is the line after he add the first command the the history but the current line is really not related to the history:  

main:

```
int main()
{
    history_ll* top;
    char userInput [CHOICE_LENGTH];
    char buff[PATH_MAX];
    int flag=1;
    cmdLine * head; 
    while (flag)
    {
        getcwd(buff, PATH_MAX); 
        printf("%s:~$ ",buff);
        fgets(userInput,MAX_INPUT, stdin);
        userInput[strlen(userInput)-1]=0;
        historyAdder(userInput,&top);
        if(strcmp(userInput,QUIT_OPTION)==0)    //segmentation fault here!
        {
            flag=0;
        }
        else
        {
            //doesn't matter
        }

    }
    return 0;
}

```

the historyAdder looks like this:

```
void historyAdder(const char *command,history_ll** top)
{
    history_ll* node;
    strcpy(node->command,command);
    node->command[strlen(command)]=0;
    if(historyLength!=0)
    {
        node->next= *top;
    }
    else
    {
        node->next= NULL;
    }
    *top = node;
    historyLength++;
}

```

**NOTE: historyLength is a global variable**

This is the structure:

```
typedef struct history_ll{
    char command[CHOICE_LENGTH];
    struct history_ll *next;
}history_ll; 

```

Thank you helpers!