Code for C-language reverse-order strings!

Source: Internet
Author: User

The time to solve the problem first comes to mind the search engine, not the brain. Now all the habits have been changed !!

// This code segment solves the reverse order of the following methods </P> <p> // original string: Who is your name; <br/> // target character :; eman ruoy Si Ohw </P> <p> # include <iostream> <br/> using namespace STD; <br/> # define max 200 </P> <p> int main () <br/> {<br/> char STR [Max]; <br/> printf ("Enter the text:"); <br/> gets (STR); </P> <p> int Len = 0; <br/> char * strlen = STR; <br/> char * Left = STR; <br/> char temp; <br/> while (* strlen ++) <br/>{< br/> Len ++; <br/>}< br/> strlen-= 2; <br/> while (left! = Strlen) <br/>{< br/> temp = * left; <br/> * left ++ = * strlen; <br/> * strlen -- = temp; <br/>}< br/> printf ("reverse string:"); </P> <p> for (INT I = 0; I <Len; I ++) <br/>{< br/> printf ("% C", STR [I]); </P> <p >}< br/> printf ("/N"); </P> <p> system ("pause "); <br/> return 0; <br/>}

 

// This code segment is in reverse order by words </P> <p> # include <iostream> <br/> # include <assert. h> <br/> using namespace STD; <br/> # define max 200 </P> <p> char * reversedtext (char * originaltext) <br/>{< br/> int textlength = 0; <br/> int wordcount = 0; <br/> int wordlength = 0; <br/> char reversingtext [Max]; <br/> int I = 0; <br/> Int J = 0; </P> <p> assert (originaltext! = NULL); <br/> textlength = strlen (originaltext); <br/> reversingtext [textlength] = '/0'; <br/> printf ("input text: /"% S/"/N ", originaltext); </P> <p> while (I <textlength) <br/> {<br/> for (j = I; (j <textlength) & (isalnum (originaltext [J]) | ('-' = originaltext [J]); j ++) <br/>{< br/> // blank block <br/>}< br/> wordlength = J-I; </P> <p> If (wordlength> 0) <br/> {<br/> memcpy (reversingtext + textlength-J, originaltext + I, wordlength ); <br/> wordcount ++; <br/> wordlength = 0; <br/>}< br/> else <br/>{< br/> // blank block <br/>}</P> <p> If (j <textlength) <br/>{< br/> reversingtext [textlength-J-1] = originaltext [J]; <br/>}< br/> else <br/>{< br/> break; <br/>}</P> <p> I = J + 1; <br/>}</P> <p> reversingtext [textlength] = '/0'; <br/> memcpy (originaltext, reversingtext, textlength ); <br/> printf ("reverse text:/" % S/"/N", originaltext); <br/> return originaltext; <br/>}</P> <p> int main () <br/> {<br/> char STR [Max]; <br/> printf ("Enter the text:"); <br/> gets (STR); </P> <p> reversedtext (STR ); <br/> printf ("/N"); </P> <p> system ("pause"); <br/> return 0; <br/>}

 

# Include "stdio. H "<br/> # include <iostream> <br/> using namespace STD; <br/> // Original: "What is your name +" <br/> // object: "name + Your is what" <br/> int main (void) <br/>{< br/> char s [] = "What is your name +"; <br/> char * A = NULL; <br/> int L = strlen (S)-1; <br/> while (L --> = 0) <br/>{< br/> If (* (S + l) = ''|! L) <br/> {<br/> A = S + L + (l )? (1): (0); <br/> while (* A & *! = '') Putchar (* A ++); <br/> putchar (''); <br/>}< br/> printf ("/N"); <br/> system ("pause"); <br/> return 0; <br/>}

The above code segment passes the test under vs2008.

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.