United States |
|
|
||
strrchr
Returns the address of the last occurrence of a given character in a null-terminated string. The terminating null character is considered to be part of the string. Format#include <string.h>Function Variants This function also has variants named _strrchr32 and _strrchr64 for use with 32-bit and 64-bit pointer sizes, respectively. See Section 1.10 for more information on using pointer-size-specific functions. Arguments
DescriptionSee also strchr in this section. Return Values
strsep
Separates strings. Format#include <string.h>Function Variants This function also has variants named _strsep32 and _strsep64 for use with 32-bit and 64-bit pointer sizes, respectively. See Section 1.10 for more information on using pointer-size-specific functions. Arguments
DescriptionThis function locates in stringp, the first occurrence of any character in delim (or the terminating '\0' character) and replaces it with a '\0'. The location of the next character after the delimiter character (or NULL, if the end of the string is reached) is stored in the stringp argument. The original value of the stringp argument is returned. Return Values
Example
strspn
Returns the length of the prefix of a string that consists entirely of characters from a set of characters. Format#include <string.h> Arguments
DescriptionThis function scans the characters in the string, stops when it encounters a character not found in charset, and returns the length of the string's initial segment formed by characters found in charset. Return Value
strstr
Locates the first occurrence in the string pointed to by s1 of the sequence of characters in the string pointed to by s2. Format#include <string.h>Function Variants This function also has variants named _strstr32 and _strstr64 for use with 32-bit and 64-bit pointer sizes, respectively. See Section 1.10 for more information on using pointer-size-specific functions. Arguments
Return Values
Example
This example produces the following results:
strtod
Converts a given string to a double-precision number. Format#include <stdlib.h>Function Variants This function also has variants named _strtod32 and _strtod64 for use with 32-bit and 64-bit pointer sizes, respectively. See Section 1.10 for more information on using pointer-size-specific functions. Arguments
DescriptionThis function recognizes an optional sequence of white-space characters (as defined by isspace ), then an optional plus or minus sign, then a sequence of digits optionally containing a radix character, then an optional letter (e or E) followed by an optionally signed integer. The first unrecognized character ends the conversion. Return Values
strtok
Locates text tokens in a given string. The text tokens are delimited by one or more characters from a separator string that you specify. This function keeps track of its position in the string between calls and, as successive calls are made, the function works through the string, identifying the text token following the one identified by the previous call. Format#include <string.h>Function Variants This function also has variants named _strtok32 and _strtok64 for use with 32-bit and 64-bit pointer sizes, respectively. See Section 1.10 for more information on using pointer-size-specific functions. Arguments
DescriptionA token in s1 starts at the first character that is not a character in the separator string s2 and ends either at the end of the string or at (but not including) a separator character. Return Values
|
#1 |
---|
#include <stdio.h> #include <string.h> main() { static char str[] = "...ab..cd,,ef.hi"; printf("|%s|\n", strtok(str, ".")); printf("|%s|\n", strtok(NULL, ",")); printf("|%s|\n", strtok(NULL, ",.")); printf("|%s|\n", strtok(NULL, ",.")); } |
Running this example program produces the following results:
$ RUN STRTOK_EXAMPLE1 |ab| |.cd| |ef| |hi| $
#2 |
---|
#include <stdio.h> #include <string.h> main() { char *ptr, string[30]; /* The first character not in the string "-" is "A". The */ /* token ends at "C. */ strcpy(string, "ABC"); ptr = strtok(string, "-"); printf("|%s|\n", ptr); /* Returns NULL because no characters not in separator */ /* string "-" were found (i.e. only separator characters */ /* were found) */ strcpy(string, "-"); ptr = strtok(string, "-"); if (ptr == NULL) printf("ptr is NULL\n"); } |
Running this example program produces the following results:
$ RUN STRTOK_EXAMPLE2 |abc| ptr is NULL $
Converts strings of ASCII characters to the appropriate numeric values.
#include <stdlib.h>Function Variants This function also has variants named _strtol32 and _strtol64 for use with 32-bit and 64-bit pointer sizes, respectively. See Section 1.10 for more information on using pointer-size-specific functions.long int strtol (const char *nptr, char **endptr, int base);
nptr
A pointer to the character string to be converted to a long .endptr
The address of an object where the function can store a pointer to the first unrecognized character encountered in the conversion process (that is, the character that follows the last character in the string being converted). If endptr is a NULL pointer, the address of the first unrecognized character is not retained.base
The value, 2 through 36, to use as the base for the conversion.
This function recognizes strings in various formats, depending on the value of the base. This function ignores any leading white-space characters (as defined by isspace in <ctype.h> ) in the given string. It recognizes an optional plus or minus sign, then a sequence of digits or letters that may represent an integer constant according to the value of the base. The first unrecognized character ends the conversion.Leading zeros after the optional sign are ignored, and 0x or 0X is ignored if the base is 16.
If base is 0, the sequence of characters is interpreted by the same rules used to interpret an integer constant: after the optional sign, a leading 0 indicates octal conversion, a leading 0x or 0X indicates hexadecimal conversion, and any other combination of leading characters indicates decimal conversion.
Truncation from long to int can take place after assignment or by an explicit cast (arithmetic exceptions not withstanding). The function call atol (str) is equivalent to strtol (str, (char**)NULL, 10) .
x The converted value. LONG_MAX or LONG_MIN Indicates that the converted value would cause an overflow. 0 Indicates that the string starts with an unrecognized character or that the value for base is invalid. If the string starts with an unrecognized character, * endptr is set to nptr.
Converts strings of ASCII characters to the appropriate numeric values. strtoll is a synonym for strtoq .
#include <stdlib.h>Function Variants This function also has variants named _strtoq32 / _strtoll32 and _strtoq64 / _strtoll64 for use with 32-bit and 64-bit pointer sizes, respectively. See Section 1.10 for more information on using pointer-size-specific functions.__int64 strtoq (const char *nptr, char **endptr, int base);
__int64 strtoll (const char *nptr, char **endptr, int base);
nptr
A pointer to the character string to be converted to an __int64 .endptr
The address of an object where the function can store a pointer to the first unrecognized character encountered in the conversion process (that is, the character that follows the last character in the string being converted). If endptr is a NULL pointer, the address of the first unrecognized character is not retained.base
The value, 2 through 36, to use as the base for the conversion.
This function recognizes strings in various formats, depending on the value of the base. This function ignores any leading white-space characters (as defined by isspace in <ctype.h> ) in the given string. It recognizes an optional plus or minus sign, then a sequence of digits or letters that may represent an integer constant according to the value of the base. The first unrecognized character ends the conversion.Leading zeros after the optional sign are ignored, and 0x or 0X is ignored if the base is 16.
If base is 0, the sequence of characters is interpreted by the same rules used to interpret an integer constant: after the optional sign, a leading 0 indicates octal conversion, a leading 0x or 0X indicates hexadecimal conversion, and any other combination of leading characters indicates decimal conversion.
The function call atoq (str) is equivalent to strtoq (str, (char**)NULL, 10) .
x The converted value. __INT64_MAX or __INT64_MIN Indicates that the converted value would cause an overflow. 0 Indicates that the string starts with an unrecognized character or that the value for base is invalid. If the string starts with an unrecognized character, * endptr is set to nptr.
Converts the initial portion of the string pointed to by nptr to an unsigned long integer.
#include <stdlib.h>Function Variants This function also has variants named _strtoul32 and _strtoul64 for use with 32-bit and 64-bit pointer sizes, respectively. See Section 1.10 for more information on using pointer-size-specific functions.unsigned long int strtoul (const char *nptr, char **endptr, int base);
nptr
A pointer to the character string to be converted to an unsigned long .endptr
The address of an object where the function can store a pointer to a pointer to the first unrecognized character encountered in the conversion process (that is, the character that follows the last character in the string being converted). If endptr is a NULL pointer, the address of the first unrecognized character is not retained.base
The value, 2 through 36, to use as the base for the conversion. Leading zeros after the optional sign are ignored, and 0x or 0X is ignored if the base is 16.If the base is 0, the sequence of characters is interpreted by the same rules used to interpret an integer constant: after the optional sign, a leading 0 indicates octal conversion, a leading 0x or 0X indicates hexadecimal conversion, and any other combination of leading characters indicates decimal conversion.
x The converted value. 0 Indicates that the string starts with an unrecognized character or that the value for base is invalid. If the string starts with an unrecognized character, * endptr is set to nptr. ULONG_MAX Indicates that the converted value would cause an overflow.
Converts the initial portion of the string pointed to by nptr to an unsigned __int64 integer. strtoull is a synonym for strtouq .
#include <stdlib.h>Function Variants This function also has variants named _strtouq32 / _strtoull32 and _strtouq64 / _strtoull64 for use with 32-bit and 64-bit pointer sizes, respectively. See Section 1.10 for more information on using pointer-size-specific functions.unsigned __int64 strtouq (const char *nptr, char **endptr, int base);
unsigned __int64 strtoull (const char *nptr, char **endptr, int base);
nptr
A pointer to the character string to be converted to an unsigned __int64 .endptr
The address of an object where the function can store a pointer to a pointer to the first unrecognized character encountered in the conversion process (that is, the character that follows the last character in the string being converted). If endptr is a NULL pointer, the address of the first unrecognized character is not retained.base
The value, 2 through 36, to use as the base for the conversion. Leading zeros after the optional sign are ignored, and 0x or 0X is ignored if the base is 16.If the base is 0, the sequence of characters is interpreted by the same rules used to interpret an integer constant: after the optional sign, a leading 0 indicates octal conversion, a leading 0x or 0X indicates hexadecimal conversion, and any other combination of leading characters indicates decimal conversion.
x The converted value. 0 Indicates that the string starts with an unrecognized character or that the value for base is invalid. If the string starts with an unrecognized character, * endptr is set to nptr. __UINT64_MAX Indicates that the converted value would cause an overflow.
Previous | Next | Contents | Index |
privacy statement and legal notices |