C language: Use pointers and function calls to compile the strcpy string copy Function

Source: Internet
Author: User

C language: Use pointers and function calls to compile the strcpy string copy Function

# Include <stdio. h> # include <assert. h>/* search for the function header file */char * my_strcpy (char * dest, const char * src)/* To pass parameters, and pass src to dest in sequence, pointer array, each address is */{char * ret = dest;/* The address received */assert (dest! = NULL); assert (src! = NULL);/* the pointer must be used to check whether the pointer is NULL by using the search function, avoid accidentally passing the empty address */while (* dest ++ = * src ++) {;} return ret;/* returns the ret as a string using char, the address */} int main () {char * p = "Hello world! "; Char arr [20];/* The reason for using the pointer p is that the array is equivalent to an address, and the completion of strcpy is equivalent to switching the addresses of the two */char * ret = my_strcpy (arr, p);/* give the p address to the array */printf ("% s", ret);/* print the string */return 0 ;}

 

Related Article

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.