Strrev () [C language library function source code]

Source: Internet
Author: User

[C language library function source code]

[This program is compiled in Dev C ++ 4.9.9.2]

/*

Reverses the order of Characters in the string.

The terminating null character remains in place.

Reverses the order of all characters in a string (excluding null characters ).

Returns the string pointer pointing to the reverse order.

*/

Char * my_strrev (char * Str)

{

Char * Right = STR;

Char * Left = STR;

Char ch;

While (* right) Right ++;

Right --;

While (left <right)

{

Ch = * left;

* Left ++ = * right;

* Right -- = CH;

}

Return (STR );

}

/*

The code I write myself is a little ambiguous and not concise,

Not so refreshing. It is worth thinking about this question.

Below is my spam code

*/

Char * my_strreverse (char * Ch)

{

Char tempch, * tch;

Int Len, I;

Tch = CH;

Len = strlen (CH );

For (I = 0; I <Len/2; I ++)

{

Tempch = * tch;

* Tch = * (TCH + len-2 * I-1 );

* (TCH + Len-2 * i-1) = tempch;

Tch ++;

}

Return ch;

}

Int main ()

{

Char STR [] = "ammana_babi ";

Puts (my_strrev (STR ));

Puts (my_strreverse (STR ));

System ("pause ");

Return 0;

}

 

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.