I am working on creating a shell similar to bash. I am running into an error when attempting to get the arguments associated with a command (ie. ls -l). I've searched online and haven't found anything useful.
char *userInCopy;
char *ret;
userInCopy = (char*)calloc(1024, sizeof(char));
ret = (char*)calloc(64, sizeof(char));
strcpy(userInCopy, userIn);
int i = 0;
while((ret = strsep(&userInCopy, " "))){
*(args + i) = (char*)calloc(strlen(ret), sizeof(char));
strcpy((*(args+i)), ret);
i++;
ret = (char*) realloc(ret, (64)* sizeof(char));
}
I get input from the user in the char userIn and that is allocated properly. I then parse through the input using strsep getting each argument individually. I can get the ls argument and -l argument but then when it goes to realloc after the -l it gives me the "realloc(): invalid pointer" error. Im lost at why this would work the first time after getting the ls argument but fails after getting the -l argument. Any suggestions?