String manipulation functions

strstr(str1,str2)

Header file: "string.h"
Definition: strstr(str1,str2) The function is used to determine whether the string str2 is a substring of str1.
Return value: The function returns the address of the first occurrence of str2 in str1 (note: the return is the address, if the string of str1 is modified after the function returns, the return value of name will correspond to the modified value); otherwise, it returns NULL.
For example:
char str2 = "cdef";
char str1 = "abcdefgh";
through the function, it will return
strstr(str1,str2) = cdefgh;

If str1 does not contain str2.
char str2 = "cxef";
char str1 = "abcdefgh";
through the function, it will return
strstr(str1,str2) = NULL;

————————————————————————————————————————————————————

strncasecmp

Header file : #include <strings.h>
Function : Compare two strings s1, s2, and ignore character case
Parameters : s1: string 1, s2: string 2, len: the maximum number of characters
to compare Return value :
If s1 and s2 match (equal), return 0.
If s1 is greater than s2, return a value greater than 0.
If s1 is less than s2, return a value less than 0.

int strncasecmp(const char *s1, const char *s2, size_t len)
{
	/* Yes, Virginia, it had better be unsigned */
	unsigned char c1, c2;
 
	if (!len)
		return 0;
 
	do {
		c1 = *s1++;
		c2 = *s2++;
		if (!c1 || !c2)
			break;
		if (c1 == c2)
			continue;
		c1 = tolower(c1);
		c2 = tolower(c2);
		if (c1 != c2)
			break;
	} while (--len);
	return (int)c1 - (int)c2;
}

————————————————————————————————————————————————————

strchr

Function prototype : extern char *strchr(char *str, char character)
Parameter description : str is a pointer to a character string, and character is a character to be searched.

The name of the library : #include <string.h>

Function : Find the position of the first occurrence of character from the string str.

Return description : return a pointer to the position of the character that appears for the first time, or NULL if it is not found.

Other notes : There is also a format char *strchr( const char *string, int c ), where the string is given in int type.
———————————————————————————————————————————————— ——

atoi

Function prototype: int atoi(const char *nptr);
Header file: #include <stdlib.h>
Function description:
  parameter nptr string, if the first non-space character exists, it is a number or a sign, then the type conversion is started , After detecting a non-digit (including the terminator \0) character, the conversion will stop and the integer will be returned. Otherwise, return zero.
———————————————————————————————————————————————— ——

Guess you like

Origin blog.csdn.net/weixin_37921201/article/details/89874260