Need strnlen().

Peter da Silva peter at graffiti.UUCP
Thu Nov 21 12:58:26 AEST 1985


> #define NUL	'\0'	/* Now, class, tell me why this is not NULL. */
> 
> 	char buffer[BUFLEN+1];
> 		...
> 	fread(buffer, 1, BUFLEN, infile);
> 	buffer[BUFLEN] = NUL;
> 	len = strlen(buffer);	/* if you must */

Uh...

	len = fread(buffer, BUFLEN, 1, infile);
	if(len==0)
		aha(endoffile);
	if(len<0)
		ohmygod(panic);
	else
		buffer[len] = NUL;

...would be much better code. Don't assume fread succeeds (it fails at least
once on almost any file :-)).
-- 
Name: Peter da Silva
Graphic: `-_-'
UUCP: ...!shell!{graffiti,baylor}!peter
IAEF: ...!kitty!baylor!peter



More information about the Comp.lang.c mailing list