I've tried it with pointers to pointers but it doesn't work
Code: Select all
parse_pipes(bufp, pipes, npipes, nextpipe, &flags)
Code: Select all
int
parse_pipes(char *buf, int (*pipes)[2], int npipes, char *nextpipe, int *flags)
{
if (npipes > 0)
*flags |= P_READ;
if ((nextpipe = strchr(buf, '|')) != NULL) {
*nextpipe++ = 0;
if (pipe(pipes[npipes]) < 0)
return(-1);
*flags |= P_WRITE;
if (strlen(buf) < 1)
return(-1);
}
return(0);
}
Code: Select all
[Aurora:~/dev/c] chris% ./shell
> ls | cd
np: cd
> bp: ls
np: (null)
bp = bufp
As you can see, my problem is that when I print nextpipe from the caller, it's still NULL and not where I pointed it to in parse_pipes. It doesn't make sense because I modify bufp yet it works properly.