I am getting a segmentation error here
<pre><code>#include &lt;stdio.h&gt;
#include &lt;unistd.h&gt;
#include &lt;regex.h&gt;

#define MAX_LINE 80
int position = 0;
int main(void)
{
char *args[MAX_LINE/2+1];
char *tokens[MAX_LINE/2+1];
char *previoustokens[MAX_LINE/2+1];
char *history[10][MAX_LINE];
int should_run = 1;
char *split;
int i = 0;

while(should_run)
{

    tokens[0]=NULL;
    tokens[1]=NULL;

    char* command, param;
    int concurrent = 0;
    printf("osh&gt;");
    fflush(stdout);
    fgets(args, sizeof(args),stdin);

    strtok(args,"\n");
    split = strtok(args," ");
    while(split!=NULL)
    {

        tokens[i]=strdup(split);
        split = strtok(NULL, " ");
        i++;

    }
    regex_t regex;
    int reti;
    char msgbuf[100];

    /* Compile regular expression */
    reti = regcomp(&amp;regex, "^![[:digit:][:digit:]*]", 0);
    if (reti) {
        fprintf(stderr, "Could not compile regex\n");
        exit(1);
    }

    /* Execute regular expression */
    reti = regexec(&amp;regex, args, 0, NULL, 0);
    if (!reti) {
        puts(tokens[0]);
        char *t = tokens[0];
        t++;
        int x;
        for(x=0;x&lt;MAX_LINE/2+1;x++)
        {
            tokens[x]=history[(int)t-1][x];
        }
    }
    regfree(&amp;regex);
}
}
</code></pre>

<p>so what this code is supposed to do is get an input and split it in to tokens and then check with regex if there is a match to the pattern if so it should copy an entry from the history and place all its belongings in tokens and this is where i get the segmentation error.</p>

<pre><code>tokens[x] = history[(int)t-1][x];
</code></pre>

<p>I'm not sure why this is not working.
Your help is much appreciated.</p>

<p>Thanks</p>