C language: Compile strcpy Functions

Source: Internet
Author: User

C language: Compile strcpy Functions
When interviewing programmers, the interviewers of many companies ask the candidates to write the library function strcpy (), which is called implementation. Many people think that this question is very simple, although such a small function can be examined from three aspects: (1) programming style (2) Error Processing (3) algorithm complexity analysis (used to improve performance) the best syntax is as follows: the Code is as follows:

# Include <stdio. h> # include <stdlib. h> # include <assert. h> // chain access char * my_strcpy (char * dest, const char * src) {// Add the source string to const, indicating that it is the input parameter assert (src! = NULL & dest! = NULL); // Add non-0 asserted char * ret = dest to the source address and target address; while (* dest ++ = * src ++); return ret; // reference the return address to facilitate chained Operations !!} Int main () {char * p = "bit-tech"; char arr [20]; // strcpy (arr, p); printf ("% d \ n ", strlen (my_strcpy (arr, p); system ("pause"); return 0 ;}

 

Write the strlen function.
 

 

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.