I'm reading Computer Systems for my CS class and I've come across a while loop condition that's puzzling me, here's the code:
int parseline(char *buf, char **argv)
{
char *delim; /* Points to first space delimiter */
int argc; /* Number of args */
int bg; /* Background job? */
buf[strlen(buf)-1] = ’ ’; /* Replace trailing ’\n’ with space */
while (*buf && (*buf == ’ ’)) /* Ignore leading spaces */
buf++;
/* Build the argv list */
argc = 0;
while ((delim = strchr(buf, ’ ’))) {
argv[argc++] = buf;
*delim = ’\0’;
buf = delim + 1;
while (*buf && (*buf == ’ ’)) /* Ignore spaces */
buf++;
}
In
while (*buf && (*buf == ’ ’)) /* Ignore spaces */
the while loop has two operands to logical && but I don't understand what is the purpose of the first operand (*buf). The second operand is checking for empty space, but I would think that the second operand by itself would suffice for the purpose of this loop.
bufcannot beNULLafter this:buf = delim + 1;