What are some important strings and memory functions of C language?
This article shows you some of the important C language strings and memory functions are how, concise and easy to understand, absolutely can make you shine, through the detailed introduction of this article I hope you can gain something.
I. String Functions 1. Find strlen for string length
size_t strlen ( const char * str );
String ends with '\0', strlen returns the number of characters that precede'\0'in the string (excluding'\0').
The string pointed to by the argument must end with '\0'.
Note that the return value of the function is size_t, which is unsigned.
Analog implementation strlen
size_t my_strlen(const char*str){ size_t count=0; while(*str) { str++; count++; }2. strcmp to compare string sizes
int strcmp ( const char * str1, const char * str2 );
The comparison starts at the position pointed to by str1 and str2, if two unequal characters are encountered or the\0 function ends and returns a value.
1 Returns numbers>0 if the first string character is greater than the second string character.
2 Returns the number =0 if the character of the first string equals the character of the second string.
3 The character of the first string is less than the character of the second string. Return ptr2 Return value>0;
ptr1=ptr2 return value =0;
ptr1