Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84 SMI; site sun.uucp Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!decwrl!sun!guy From: guy@sun.uucp (Guy Harris) Newsgroups: net.lang.c Subject: Re: index Message-ID: <2527@sun.uucp> Date: Tue, 30-Jul-85 21:38:57 EDT Article-I.D.: sun.2527 Posted: Tue Jul 30 21:38:57 1985 Date-Received: Fri, 2-Aug-85 06:30:58 EDT References: <652@hou2e.UUCP> <169@kitty.UUCP> Organization: Sun Microsystems, Inc. Lines: 31 > > What is the BSD function "index" supposed to do? Does anyone > > know the equivalent on a System V Release 2 machine? > > I have System V Release 2.2 on 3B2's and have used the index(3F) function > in Fortran applications. The function is called from a Fortran program and > returns the location (i.e., integer character count) of the substring > in the character string . The user was referring to the C library function "index", not the Fortran function. The C function searches for a character in a string, not a string in another string (as the Fortran and PL/I functions of that name do), which is why I (mildly) approve of the renaming to "strchr" in System III (or earlier). > Index is similar to the C language function 'strspn'. No, it isn't. "strspn" looks for any of the characters contained in the second argument string in the first argument string, while the Fortran and PL/I "index" look for the second argument string in its entirety. strspn(, " \t\n") will return the address of the first blank, tab, or newline in , while index(, " \t\n") will (in Fortran or PL/I, but NOT in C) look for the first occurrence of a blank followed by a tab followed by a newline in . Guy Harris