Previous | Table of Contents | Next

Page 1039

RETURN VALUE

The strspn() function returns the number of characters in the initial segment of s, which consist only of characters from accept.

The strcspn() function returns the number of characters in the initial segment of s, which are not in the string reject.

CONFORMS TO

SVID 3, POSIX, BSD 4.3, ISO 9899

SEE ALSO

index(3), memchr(3), rindex(3), strchr(3),
strpbrk(3), strsep(3), strstr(3), strtok(3)

12 April 1993

strstr

strstr—Locates a substring

SYNOPSIS

#include <string.h>
char *strstr(const char *haystack, const char *needle);

DESCRIPTION

The strstr() function finds the first occurrence of the substring needle in the string haystack. The terminating \0 characters are not compared.

RETURN VALUE

The strstr() function returns a pointer to the beginning of the substring, or NULL if the substring is not found.

SEE ALSO

index(3), memchr(3), rindex(3), strchr(3), strpbrk(3), strsep(3), strspn(3), strtok(3)

GNU, 12 April 1993

strtod

strtod—Converts ASCII string to double

SYNOPSIS

#include <stdlib.h>
double strtod(const char *nptr, char **endptr);

DESCRIPTION

The strtod() function converts the initial portion of the string pointed to by nptr to double representation.

The expected form of the string is optional leading whitespace as checked by isspace(3), an optional plus (+) or minus sign

(-) followed by a sequence of digits optionally containing a decimal point character, optionally followed by an exponent. An exponent consists of an E or e, followed by an optional plus or minus sign, followed by a nonempty sequence of digits. If the locale is not C or POSIX, different formats may be used.

Page 1040

RETURN VALUES

The strtod function returns the converted value, if any.
If endptr is not NULL, a pointer to the character after the last character used in the conversion is stored in the location referenced by endptr.

If no conversion is performed, zero is returned and the value of nptr is stored in the location referenced by endptr.

If the correct value would cause overflow, plus or minus HUGE_VAL is returned (according to the sign of the value), and ERANGE is stored in errno. If the correct value would cause underflow, zero is returned and ERANGE is stored in errno.

ERRORS

ERANGE Overflow or underflow occurred.

CONFORMS TO

ANSI C

SEE ALSO

atof(3), atoi(3), atol(3), strtol(3), strtoul(3)

BSD man page, 4 March 1996

strtok

strtok—Extracts token from string

SYNOPSIS

#include <string.h>
char *strtok(char *s, const char *delim);

DESCRIPTION

A token is a nonempty string of characters not occurring in the string delim, followed by \0 or by a character occurring in delim.

The strtok() function can be used to parse the string s into tokens. The first call to strtok() should have s as its first argument. Subsequent calls should have the first argument set to NULL. Each call returns a pointer to the next token, or NULL when no more tokens are found.

If a token ends with a delimiter, this delimiting character is overwritten with a \0 and a pointer to the next character is saved for the next call to strtok. The delimiter string delim may be different for each call.

BUGS

This function modifies its first argument. The identity of the delimiting character is lost.

RETURN VALUE

The strtok() function returns a pointer to the next token, or NULL if there are no more tokens.

CONFORMS TO

SVID 3, POSIX, BSD 4.3, ISO 9899

SEE ALSO

index(3), memchr(3), rindex(3), strchr(3),
strpbrk(3), strsep(3), strspn(3), strstr(3)

GNU, 10 February 1996

Page 1041

strtol

strtol—Converts a string to a long integer

SYNOPSIS

#include <stdlib.h>
long int strtol(const char *nptr, char **endptr,int base);

DESCRIPTION

The strtol() function converts the string in nptr to a long integer value according to the given base, which must be between 2 and 36 inclusive, or be the special value 0.

The string must begin with an arbitrary amount of whitespace (as determined by isspace(3)) followed by a single optional + or - sign. If base is zero or 16, the string may then include a 0x prefix, and the number will be read in base 16; otherwise, a zero base is taken as 10 (decimal) unless the next character is 0, in which case it is taken as 8 (octal).

The remainder of the string is converted to a long int value in the obvious manner, stopping at the first character that is not a valid digit in the given base. (In bases above 10, the letter A in either upper- or lowercase represents 10, B represents 11, and so forth, with Z representing 35.)

If endptr is not NULL, strtol() stores the address of the first invalid character in *endptr. If there were no digits at all, strtol() stores the original value of nptr in *endptr. (Thus, if *nptr is not \0 but **endptr is \0 on return, the entire string is valid.)

RETURN VALUE

The strtol() function returns the result of the conversion, unless the value would underflow or overflow. If an underflow occurs, strtol() returns LONG_MIN. If an overflow occurs, strtol() returns LONG_MAX. In both cases, errno is set to ERANGE.

ERRORS

ERANGE The given string was out of range; the value converted has been clamped.

CONFORMS TO

SVID 3, BSD 4.3, ISO 9899

SEE ALSO

atof(3), atoi(3), atol(3), strtod(3), strtoul(3)

BUGS

Ignores the current locale.

GNU, 10 June 1995

strtoul

strtoul—Converts a string to an unsigned long integer.

SYNOPSIS

#include <stdlib.h>
unsigned long int strtoul(const char *nptr, char **endptr,
int base);

Previous | Table of Contents | Next

1