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!