1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#define MAX_LINE 80
void parseInput(char* args[], char* input)
{
int i = 0;
char* token = strtok(input, " ");
while (token != NULL) {
args[i] = token;
printf("%d - %s\n", i, args[i]);
token = strtok(NULL, " ");
i++;
}
}
int main(void)
{
char *history;
char inputBuffer[MAX_LINE];
char *args[MAX_LINE/2+1];
int should_run = 1, i;
while(should_run)
{
printf("osh> ");
fflush(stdout);
fgets(inputBuffer, MAX_LINE, stdin);
//lets stop when quit or exit is written
if(!strcmp(inputBuffer, "quit\n") || !strcmp(inputBuffer, "exit\n"))
{
should_run = 0;
break;
}
printf("Read from input: %s\n", inputBuffer);
printf("%d\n", strlen(inputBuffer));
parseInput(&args[MAX_LINE/2+1], inputBuffer);
}
//when I here try this, it works
args[0] = "zero";
args[1] = "one"; //etc
for(i = 0; i<((MAX_LINE/2)+1); i++)
printf("%d - %s\n", i, args[i]);
return 0;
}
|