Reverse C string

Source: Internet
Author: User

Topic:

    1. Write code to reverse a c-style String (c-string means this "ABCD" is represented as five characters, including the null C Haracter)

Reference solution: It is easier to remove the thought of the array and do it with the Sentinel of the pointer.

First time Solution:

After the string is traversed, the length is then swapped.

////main.cpp//Reverse////Created by Lexnewgate on 15/11/6.//copyright©2015 year lexnewgate. All rights reserved.//#include<iostream>#include<vector>voidREVERSESTR (Char*str) {    intI=0;  for(i=0; * (str+i)! =' /'; i++) {            }     for(intj=0; j<i/2; J + +) {        Chartemp=* (str+j); * (STR+J) =* (str+i-j-1); * (str+i-j-1)=temp; }    return ;}intMainintargcConst Char*argv[]) {        Charp[]="ABCDCXDSWSW";    REVERSESTR (P); printf ("%s\n", p); return 0;}

Reverse C string

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.