NULL as a string terminator (was Re: Get process name... )

Gary Duzan gdtltr at freezer.it.udel.edu
Sat Aug 4 16:15:40 AEST 1990


In article <707 at mtune.ATT.COM> jrw at mtune.ATT.COM (Jim Webb) writes:
=>
=>	char psbuf[64];
=>	char command[15];
=>	FILE *ps;
=>	
=>	/* I'm sure this could be done better in perl :-) */
=>	sprintf(psbuf,"ps -p%d|awk '{/PID/ {next} { print $4 }'",getpid());
=>	ps=popen(psbuf,"r");
=>	fgets(command,15,ps);
=>	pclose(ps);
=>	command[strlen(command)-1]=NULL; /* chop off the \n */
                                   ^^^^
   Pardon me for reopening the NULL discussion, but won't this give a warning
if NULL is #defined (void *) 0? If it doesn't, should it? Assigning a pointer
to a char is certainly a questionable thing to do.

                                        Gary Duzan
                                        Time  Lord
                                    Third Regeneration



--
                          gdtltr at freezer.it.udel.edu
   _o_                    --------------------------                      _o_
 [|o o|] If you can square, round, or cube a number, why not sphere it? [|o o|]
  |_O_|         "Don't listen to me; I never do." -- Doctor Who          |_O_|



More information about the Comp.unix.questions mailing list