C Language Implementation strcpy

Source: Internet
Author: User

Strcpy.h:

1 #ifndef Strcpy_h2 #defineStrcpy_h3 4#include <stdio.h>5 6 Char*cat_strcpy (Char*DST,Const Char*src) {7     if(NULL = = SRC | | NULL = =src)8         returnNULL;9 Ten     Char*s = (Char*) src, *d =DST; One  A      while((*d++ = *s++)! =' /') { -         // do nothing -     } the*d =' /'; -  -     returnDST; - } +  - #endif

Main

12#include"Strcpy.h"3 4 5 voidtest_strcpy ();6 7 intMain () {8 test_strcpy ();9 Ten     return 0; One } A  -  - voidtest_strcpy () { the     Char*SRC ="test_strcpy"; -     Chardest[ -] = {0 }; - cat_strcpy (dest, SRC); -  +printf"%s\n", dest); -}

strcpy (STR1,STR2) function can copy content from str2 to str1, Why do I need function return value ? It should be easy to implement chain expressions, such as:

int length = strlen (strcpy (STR1,STR2));

C Language Implementation strcpy

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.