The prototype of string manipulation function to realize __ function

Source: Internet
Author: User
Connect two char types: char * __cdecl strcat (char * DST, const char * src) {char * cp = DST; 
         while (*CP) cp++;

         while (*cp++ = *src++);
return (DST);
         }//C language standard library function strcpy, copying a string starting from the SRC address and containing the ' ' Terminator to the address space starting with dest: char * __cdecl strcpy (char * DST, const char * src) {
         char * cp = DST;          
	 while (*cp++ = *src++);
return (DST); }//Find first occurrence of character C in string s char * __cdecl STRCHR (const char * string, int ch) {while (*string && *string!)
         = (char) ch) string++;
         if (*string = = (char) ch) return ((char *) string);
return (NULL); /*c/c++ function, compares two strings, sets these two strings to be str1,str2, if STR1=STR2, returns 0, returns a negative number if str1<str2, and returns a positive number if str1>str2.

         * * int __cdecl strcmp (const char * src,const char * DST) {int ret = 0; while (!

         (ret = * (unsigned char *) src-* (unsigned char *) DST) && *dst) ++src, ++DST;
        if (Ret < 0)         ret =-1;

         else if (Ret > 0) ret = 1;
return (ret);
     }//Find string length size_t __cdecl strnlen (const char *STR, size_t maxsize) {size_t n;
     
     for (n = 0; n < maxsize && *str; n++, str++);
return n;
         }//To String length size_t __cdecl strlen (const char * str) {const char *eos = str;
         while (*eos++);
return (EOS-STR-1);
     }//Copy security Functions errno_t __cdecl strcpy_s (_char *_dest, size_t _size, const _char *_src) {_char *p;

     size_t available;
     _validate_string (_dest, _size);

     _validate_pointer_reset_string (_SRC, _dest, _size);
     p = _dest;
     Available = _size; while ((*p++ = *_src++)!= 0 &&--available > 0) {} if (available = 0) {_reset_string (_des
         T, _size);
     _return_buffer_too_small (_dest, _size);
     } _fill_string (_dest, _size, _size-available + 1);
_return_no_error; } char * __cdecl strncpy (char * dest, constchar * source, size_t count) {char *start = dest;
         while (count && (*dest++ = *source++))//copy str count--;

         if (count) while (--count) *dest++ = ';
 return (start); The/*STRSTR (STR1,STR2) function is used to determine whether a string str2 is a str1 substring. If it is, the function returns the address that str2 first appears in str1, otherwise, returns NULL.
         */char * __cdecl strstr (const char * str1, const char * str2) {char *CP = (char *) str1;
         Char *s1, *S2;

         if (!*STR2) return ((char *) str1);
                 while (*CP) {S1 = CP;

                 S2 = (char *) str2; while (*s1 && *s2 &&! (

                 *S1-*S2)) s1++, s2++;

                 if (!*S2) return (CP);
         cp++;
return (NULL);
The//STRSTR (STR1,STR2) function is used to determine whether a string str2 is a substring of str1. If so, the function returns the last occurrence of the str2 in str1 (that is, the first occurrence from right to left); otherwise, returns NULL. char * __cdecl STRRCHR (const char * string, int ch) {ChaR *start = (char *) string; while (*string++);
         /* Find end of String * */while (--string!= start && *string!= (char) ch);

         if (*string = = (char) ch) return ((char *) string);
return (NULL);

 }


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.