C pointer to implement string Inversion

Source: Internet
Author: User

C pointer to implement string Inversion

Question requirements:

 

Program writing: input a string from the keyboard at will and output the string.
Then, store the string in reverse order and then output it. It must be completed with a character pointer.

Code:

 

 

// Solution 1 # include

 
  
# Include

  
   
Int main () {char a [20] = {0}, B [20] = {0}, * p1, * p2; printf ("any input string: "); // memset (B, 0X00, sizeof (B); gets (a); p1 = a; p2 = B + strlen (a)-1; for (; * p1! = '\ 0'; p1 ++, p2 --) * p2 = * p1; * p2 =' \ 0'; printf ("string a is: % s \ n ", a); printf ("string B is: % s \ n", B); return 0 ;}// solution 2 # include

   
    
# Include

    
     
# Define MAXN 1000 void reverse (char * str) {char * p = str + strlen (str)-1; char temp; while (str

     

      

 

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.