C/C++ 字串反轉
C/C++ 字串反轉
資料來源:https://mp.weixin.qq.com/s/lZ9SsObIMoncjs4ZoyLRlA
線上編譯:https://www.tutorialspoint.com/compile_c_online.php
Code:
#include <stdio.h> void rechange_str(char *str) { int i, len; char tmp; if (NULL == str) { return ; } len = strlen(str); for (i = 0; i < len/2; i ++) { tmp = str[i]; str[i] = str[len-i-1]; str[len-i-1] = tmp; } } int main() { char str[20] = "hello,world"; printf("%s\n",str); rechange_str(str); printf("%s\n",str); return 0; }