S
sugaray
Hi, I just came upon this code snippet which parses a string stored in buf
with comma(,) as delimiter and store each substring into args, the question
I'm having here is that I don't get why in the first while-statement the OP
cast the NULL to a (long), isn't *buf a char ? and another question is what's
the purpose of NULL in string manipulation, and how to test to see if an input
string is empty ? Thanx for your help.
void parse (char *buf, char **args) {
while (*buf != (long) NULL ) {
while ( *buf == ',' )
*buf++ = (long) NULL ;
*args++ = buf;
while ( (*buf != (long) NULL) && (*buf != ',') )
buf++;
}
*args = NULL;
}
with comma(,) as delimiter and store each substring into args, the question
I'm having here is that I don't get why in the first while-statement the OP
cast the NULL to a (long), isn't *buf a char ? and another question is what's
the purpose of NULL in string manipulation, and how to test to see if an input
string is empty ? Thanx for your help.
void parse (char *buf, char **args) {
while (*buf != (long) NULL ) {
while ( *buf == ',' )
*buf++ = (long) NULL ;
*args++ = buf;
while ( (*buf != (long) NULL) && (*buf != ',') )
buf++;
}
*args = NULL;
}