Here's a working version for you:
Code:
#include <stdio.h>
#include <string.h>
char history[100][100];
int historyCount;
char *readCommandLine(void)
{
static char command[100];
char *p;
if (fgets( command, sizeof( command ), stdin ))
{
if ((p = strchr(command, '\n')) != NULL)
{
*p = '\0';
}
strcpy(history[historyCount], command);
historyCount++;
return command;
}
return NULL;
}
int main(void)
{
char *cmdLine;
int i;
while ((cmdLine = readCommandLine()) != NULL && strcmp(cmdLine, "quit") != 0)
{
printf ("You entered command: >%s<\n", cmdLine);
}
for (i = 0; i < historyCount; i++)
{
printf ("Command history %d >%s<\n", i, history[i]);
}
return 0;
}
/*
Output:
this is a command
You entered command: >this is a command<
blah blah
You entered command: >blah blah<
quit
Command history 0 >this is a command<
Command history 1 >blah blah<
Command history 2 >quit<
*/