I am trying to write a function that is given a string of text (which is to be a shell command) and now I just need to extract words, so delete spaces and save each word in a pointer to pointer to char. My idea was to do it this way, but gcc compilers gives back a warning that "return from incompatible pointer type"
Code:
char **getargs(char *command)
{
static char arguments[MAXARG][CMDLENGTH];
int i = 0, word = 0, letter = 0, status = OUT;
while(command[i] != '\0')
{
if(isspace(command[i]) && status == IN)
{
arguments[word][letter] = '\0';
letter = 0;
word++;
status = OUT;
i++;
}
else if(!isspace(command[i]) && status == OUT)
{
arguments[word][letter] = command[i];
status = IN;
letter++;
i++;
}
else if(!isspace(command[i] && status == IN))
{
arguments[word][letter] = command[i];
letter++;
i++;
}
else if(isspace(command[i]) && status == OUT)
i++;
}
return arguments;
}
EDIT: Additionally, I have also figured out that in order to return a pointer that was declared locally it needs to be declared as static, why is that?