Why (long)NULL ?

From: sugaray (ruicui_at_sohu.com)
Date: 02/29/04


Date: 28 Feb 2004 22:30:15 -0800

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;
        
        }



Relevant Pages

  • Re: Help needed with macros: Brain turning to jelly
    ... '(('string buf) ) ... QUOTE their argument, usually. ... :pointer args ...
    (comp.lang.lisp)
  • Re: newbie question
    ... avoid memory allocations: the data can be swapped in-place. ... // modifies the contentes of 0-terminated 'buf' as described above ... string swapHalves ...
    (comp.lang.cpp)
  • Re: difference between casting and atol,atoi functions
    ... The first is ill-formed since buf may not be suitably ... character code 255 need not represent a digit ... or a text string ... Note that the size and representation of a signed long can ...
    (comp.lang.c)
  • Re: difference between casting and atol,atoi functions
    ... The first is ill-formed since buf may not be suitably ... character code 255 need not represent a digit ... or a text string ... Note that the size and representation of a signed long can ...
    (alt.comp.lang.learn.c-cpp)
  • Re: GetWindowText - Windows API
    ... GetWindowText has a third parameter, ie the length of the buffer where it ... string @lpClassName, string @WindowName ... local buf, nchars ...
    (microsoft.public.fox.programmer.exchange)