Ok I used the strcmp(csh, "bye") on the outer while loop but it does not exit the while loop when I type bye. It isn't recognizing that they are equal.
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
main()
{
char *cptr, *csh;
char buffer[256], bye[4] = "bye";
char **args = NULL;
int nargs = 0;
printf("sh%% ");
cptr = fgets(buffer, 256, stdin);
csh = strtok(buffer, " ");
while(strcmp(csh, "bye") != 0)
{
while(csh != NULL)
{
args = realloc(args, sizeof(char *)*(nargs + 1));
args[nargs] = malloc(strlen(csh) + 1);
strcpy(args[nargs], csh);
nargs++;
csh = strtok(NULL, " ");
}
nargs = 0;
printf("sh%% ");
cptr = fgets(buffer, 256, stdin);
csh = strtok(buffer, " ");
}
}
I tried using strcmp(csh, "bye") and strcmp(csh, bye) with bye being predefined and either way it always returns that they are unequal.