NULL as a string terminator

Wade Guthrie evil at arcturus.uucp
Wed Aug 8 07:01:52 AEST 1990


Gary Duzan writes:
>=>     char command[15];
>=>     command[strlen(command)-1]=NULL; /* chop off the \n */

and Doug Gwyn says:
> You're correct; the example code would happen to work with the traditional
> definition of NULL as plain 0, but not if it's defined as ((void*)0).

That is why I have made it a practice to define a macro:

#define	NULLchar	'\0'

in order to reduce the confusion/broken code.  One thing that I find
helpful is to have a header file called "global.h" or "wade.h" that
has a bunch of definitions I use in all my code.  This file is included
by every C file and has things in it like:

#define	YES	1
#define	NO	0
#ifdef	MAIN_MODULE
	int		my_debug = 0;
#else
	extern int 	my_debug;
#endif

I find this to be very useful (the file is actually quite a bit bigger
than this, but I don't think anyone really cares. . .)
-- 
Wade Guthrie (evil at arcturus.UUCP)    | "He gasped in terror at what sounded
Rockwell International; Anaheim, CA  | like a man trying to gargle while
My opinions, not my employer's.      | fighting off a pack of wolves"
                                     |                Hitchhiker's Guide



More information about the Comp.lang.c mailing list