C-language string copy Function

Source: Internet
Author: User

Today, I saw a C-language string copy interview question on csdn. The question is as follows:

The input string must be output in reverse order, and third-party variables cannot be used. The prototype of the function is char * strncopy (const char * Source, char * DEST), and database functions are not required,

As required, I wrote the following program:

# Include <stdio. h> # include <stdlib. h> char * strncopy (const char * Source, char * DEST); int main (INT argc, char * argv []) {char * Source = "1241654654 "; char Dest [strlen (source)]; printf ("% d \ n", strlen (DEST); strncopy (source, DEST); printf ("% s \ n ", DEST); System ("pause"); Return 0;}/***** reverse copy */char * strncopy (const char * Source, char * DEST) {If (source! = NULL & DEST! = NULL) {While (* ++ source); While (* DEST ++ = * -- source); Return DEST;} return NULL ;}
 

The above Code seems to have implemented the function, but there is still a fatal error, that is, it does not determine the length of the dest, and does not consider whether the target string can accommodate the next source.

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.