Nine
library functions for string processing
character processing function:<ctype.h>
int isdigit (int ch);//Whether is a number, that is, whether CH is a character in 0-9
int isxdigit (int ch);//is a hexadecimal number, that is, whether CH is a 0-9 a-Z-Z character
int isalpha (int ch);//Is the letter
int isalnum (int ch);//Whether is a letter or a number
int islower (int ch);//is a lowercase letter
int isupper (int ch);//Uppercase
int tolower (int ch);//Convert to lowercase letter
int toupper (int ch);//converted to uppercase letters
string conversion function:<stdlib.h>
1, converting characters to numbers:
(Preferably a pure numeric string conforming to the requirement, if the number is mixed with the letter, the number must be in front)
Double atof (char *str); Converts a string str to a double number
int atoi (char *str); Converts string str to int-type numbers
Long Atol (char *str); Converts string str to a long int number
2, number converted to character:
char * itoa (int digit, char *deststr, Intradix); Converts an int numeric digit to a radix into a string deststr
char * LTOA (long digit, char *deststr, Intradix); Similarly converts a long number to a string
char * ULTOA (long digit, char *deststr,int radix); Similarly converts unsignedlong numbers to strings
"The above library function can be used for the conversion of the system"
Similar functions include:
Double Strtod (char *, char * *);
Long Strtol (char *, char * *, int);
unsigned long strtoul (char *, char * *, int);
★ String manipulation function:<string.h>
char * strcpy (char *s1, char *s2); Copies the string s2 into the array s1.
char * strncpy (char *s1,char *s2); Copies the maximum n characters of a string S2 into an array s1
char * strcat (char *s1, char * s2); connect string s2 to S1 tail of string
char * STRNCAT (char *s1, char *s2, SIZE_TN); To concatenate up to n characters in a string S2 after S1
"Note: All of these require sufficient storage space for the target character array."
string comparison function:<string.h>
int strcmp (char *s1, char *s2),//comparison string s1,s2. If S1 equals less than or greater than S2, return 0, negative, positive
int stricmp (char *s1, char *s2);//case-insensitive comparison of two strings
int strncmp (char *s1, char *s2, size_t n);//compare up to n characters of two strings
String Lookup function:<string.h>
Char *strchr (char *str, int ch);//in String str Find the first occurrence of the character ch, if found, returns a pointer to ch in STR, otherwise null
Char *strrchr (char *str, int ch);//Find the last occurrence of the character ch in the string str (that is, look forward from the back)
Char *strstr (char *str1, char *str2);//Find the first occurrence of a string str2 in a string str1
Char *strpbrk (char *str2, char *str2);//Find the location of the first occurrence of any character in the string str1 in the string str2.
Other functions:
Char *strrev (char *); String Reverse function
size_t strlen (char * str);//measuring string str length
Note:
strncpy (), Strncat (), strncmp (), these functions can operate on only two different strings, cannot operate on different parts of the same string, and you can use memory functions if you need to.
If the target string is initially empty, strncat () can perform many functions. Can replace the function of strncpy (),
You can also extract substrings and so on.
Memory Functions
"Memory functions operate directly on memory, not only to handle strings, but also to handle any type of array, structure, and so on." 】
In standard C, these functions are considered to be part of a string function and are declared in the header file string.h.
void * memcpy (void *dest, const void *SRC, size_t n);
Copy n bytes to dest from the SRC address and return the value of the address dest
void * Memmove (void *dest, const void *SRC, size_t n);
The function is the same as the previous function, except that the Memmove function performs the operation correctly when the source and destination memory regions overlap.
void * MEMCHR (const void *ptr, int val, size_t len);
Searches for the first occurrence of the Val value in the first Len character after address ptr. If Val is found, it returns a pointer to the first character that contains the Val value, otherwise a null character is returned.
(each character is compared according to an expression (unsigned char) c = = (unsigned char) val)
void * memset (void * ptr, int val, size_tlen);
To copy Val to the Len character starting at PTR, the character specified by PTR is considered to be a Unsignedchar type
int memcmp (const void * PTR1, const void * ptr2, size_t len);
Compares the first Len characters of the PTR1 with the first Len characters of the PTR2. If the first string is less than the second character string in dictionary order, MEMCMP returns a negative value.
"PostScript" my list of C books
"National Computer grade two C language"
"C Language University Course"
"C and Pointers"
"C Language Depth Analysis"
"You must know the 495 C language Problem"
"C Expert Programming"
C Pitfalls and pitfalls (if you read the book carefully, it doesn't make any sense, it's not recommended)
High quality C + + Programming Guide
"C Language Reference manual" (as a dictionary, beginners do not recommend)
"C Standard Library" (not recommended)