In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use the str function of c language". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use the str function of c language".
Strlen:
Used to find the length of a string, starting with the first character and ending with'\ 0'.'\ 0' is not counted as the total length.
Function implementation:
Size_t my_strlen (const char* ptr) {assert (ptr); const char* ptx = ptr; while (* (+ + ptx)); return (size_t) (ptx-ptr);} strcmp:
Used to compare the size of two strings, note that size does not refer to the length of the string, but from the first character to compare the size of the character. This function returns an int value, which varies from compiler to compiler. But the positive and negative are consistent. When the first is greater than the second, a positive value is returned, less than a negative value, and equality returns 0.
Function implementation:
Int my_strcmp (const char* str1,const char* str2) {assert (str1 & & str2); while ((! (* str1-* str2)) & & (* (str1++)) * (* (str2++); return (int) (* str1-* str2);} strcpy:
Used to copy strings.
Function implementation:
Char* my_strcpy (char* dest,const char* source) {assert (dest & & source); char* result = dest; while (* (dest++) = * (source++)); return result;} strcat:
Used to append a string to the end of the target string.
Function implementation:
Char* my_strcat (char* a, const char* b) {assert (a & & b); char* tmp = a; while (* (+ + a)); while (* (aura +) = * (baked +)); * a ='\ 0mm; return tmp;} strstr:
Used to find one string within another. This is related to the KMP algorithm.
Function implementation:
Const char* my_strstr (const char* a, const char* b) / / an is a long string b is a short string {char* cp = (char*) a; char* S1; char* S2; if (! * b) return a; while (* cp) {S1 = cp; S2 = (char*) b While (* S1 & & * S2 & &! (* S1-* S2)) {S1 return cp; cp++; return cp; cp++;} return NULL;} atoi:
This function is interesting because it converts the numeric string of a string to an int value.
Function implementation:
Int my_atoi (const char* str) {assert (str); int num = 0; int result = 0; const char* tmp = str; while (* str & & * str! ='.') {num++; str++ } while (num--) {result + = (* tmp -'0') * (int) pow (10, num); tmp++;} return result;}
Strncpy,strncmp,strncat:
All three functions limit the number of characters, and the function is the same.
Function implementation:
Char* my_strncpy (char* dest, const char* sou, size_t num) {assert (dest & & sou); char* tmp = dest; while ((num--) & (* (dest++) = * (sou++); return tmp;} char* my_strncat (char* a, const char* b, int n) {assert (a & b); char* tmp = a While (* (+ + a)); while ((NMI -) & & (* (averse +) = * (baked +); * a ='\ 0mm; return tmp;} int my_strncmp (const char* str1, const char* str2,int n) {assert (str1 & & str2) While ((! (* str1-* str2)) & & ((* (str1++)) * (* (str2++) & & (NMurray -)); return (int) (* str1-* str2) Thank you for reading, the above is the content of "how to use the str function of c language". After the study of this article, I believe you have a deeper understanding of how to use the str function of c language, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.