The practice program of C on Point

Source: Internet
Author: User
// Reverse character arrangement // vision 1.2 # include <stdio. h> void reverse_string (char * Str) {char * string; // the first character position char * last_char; // The last character position // For (last_char = STR ;; last_char ++) // If (* last_char = '\ 0') // break; // For (last_char = STR; * last_char! = '\ 0'; last_char ++) //;/*** set last_char to store the last character position */For (last_char = & STR [0]; * last_char! = '\ 0'; last_char ++); string = & STR [0]; last_char --; /*** increase the value of the pointer pointing to the position before and after switching and then decrease the pointer */while (string <last_char) {char temp; temp = * string; * string ++ = * last_char; * last_char -- = temp;} printf ("% s", STR);} int main (void) {char STR [10] = {"abcdef"}; reverse_string (STR); Return 0 ;}
If you do not use a library function, you can break out some functions in this library function. It's just a bit confusing. This is the final version, but in a previous version, the output is always only half the length of the source string, and it is also reversed. I don't understand it. I hope you can tell me when you see it. Thank you ~ The source code is as follows:
// Reverse character arrangement // vision 1.2 // Why is the program result incorrect? // At present, I guess the problem lies in the array pointer. // directly operate on the pointer of the original array, you should find an intermediate volume storage start pointer. // To be continued... # include <stdio. h> void reverse_string (char * Str) {char * last_char; // The last character position // For (last_char = STR; last_char ++) // If (* last_char = '\ 0') // break; // For (last_char = STR; * last_char! = '\ 0'; last_char ++) //;/*** set last_char to store the last character position */For (last_char = & STR [0]; * last_char! = '\ 0'; last_char ++); last_char --;/*** increase the pointer before and after the value of the pointer pointing to the position before and after switching */while (STR <last_char) {char temp; temp = * STR; * STR ++ = * last_char; * last_char -- = temp;} printf ("% s", STR);} int main (void) {char STR [10] = {"abcdxuf"}; reverse_string (STR); Return 0 ;}
There is only one more intermediate variable. Why?

The practice program of C on Point

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.