Need strnlen().

Joseph S. D. Yao jsdy at hadron.UUCP
Thu Nov 21 06:36:57 AEST 1985


OK.  Let's all stop arguing over whether this routine should exist.

#define NUL	'\0'

/*
** This routine, for whatever reason, wants to calculate the length
** of string 's' but be sure that it stops before element 'n'.
*/
int strnlen(s, n)
  register char *s;
  register int n;
{
	register int i;

	for (i = 0; i < n; i++) {
		if (*s++ == NUL)
			break;
	}
	return(i);
}

There.  It exists.  If you must use it, do so.  I will try not to,
but may have to some day.  Fair 'nuff?
-- 

	Joe Yao		hadron!jsdy at seismo.{CSS.GOV,ARPA,UUCP}



More information about the Comp.lang.c mailing list