C string inversion, XCode compilation, and xcode reversal

Source: Internet
Author: User

C string inversion, XCode compilation, and xcode reversal

I am studying ios development. When I learned c in the early stage, the regular method directly reverses the value of the array and can only be used for non-Chinese characters. Otherwise, garbled characters may occur,

I found some information on the Internet, maybe because the IDE is inconsistent and cannot get the desired value. It took some time to change it.

 

// String inversion char * MyInverseStr (char _ soruce []) {int x = strlen (_ soruce); // char strrRev [strlen (char *) _ soruce)]; // sizeof (_ source) and sizeof (char *) _ source) cannot obtain the correct value. strlen (char *) _ source), strlen (_ source) cannot be used directly as a variable. You must first assign a value to the specified variable char strrRev [x + 1]; // int j = 0; for (int I = strlen (_ soruce)-1; I> = 0; I --) {if (_ soruce [I]> 127 | _ soruce [I] <0) // is a Chinese character {strrRev [j] = _ soruce [I-2]; strrRev [j + 1] = _ soruce [I-1]; strrRev [j + 2] = _ soruce [I]; I-= 2; j + = 2 ;} else {strrRev [j] = _ soruce [I];} j ++;} strrRev [j] = '\ 0'; return strrRev ;}

 

Do not spray for new users!

Related Article

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.