Invert string function reverse

Source: Internet
Author: User

Invert string function reverse: Used to invert the positions of characters in string S,
If the initial value of the original string is 123456, you can use the reverse function to put it upside down to 654321,
The procedure is as follows:
# Include <stdio. h>
# Include <string. h>
Void reverse (char s [])
{
Int C, J, I;
For (I = 0, j = strlen (S)-1; I <j; I ++, j --) // completes the inversion function, the string Terminator '/0' is not included'
{
C = s [I];
S [I] = s [J];
S [J] = C;
}
}
Main () // main function, used to test the reverse function
{
Char s [] = "123456 ";
Reverse (s); // call the inverted Function
Printf ("Inverted string: % s/n", S); // output inverted string
}


The running result is as follows; 654321

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.