本帖最后由 bin554385863 于 2019-12-1 18:01 编辑 #include <stdio.h>
#include <string.h>
void fun(char *str, size_t sz)
{
for (size_t i = 1; i < sz - 2; i++)
{
for (size_t j = 1; j < i; j++)
{
if (str[j] < str[i])
{
char t = str[j];
*(str + j) = str[i];
*(str + i) = t;
}
}
}
}
int main(int argc, char const *argv[])
{
char str[8] = "1234567";
printf("原字符串: %s\n", str);
fun(str, 8);
printf("改变之后: %s", str);
return 0;
}
========================================
Microsoft Windows [版本 10.0.18363.476]
(c) 2019 Microsoft Corporation。保留所有权利。
E:\Users\admin\Documents\VScode\Code>c:\Users\admin\.vscode\extensions\ms-vscode.cpptools-0.26.1\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-j0q0loxd.cmr --stdout=Microsoft-MIEngine-Out-i1vcexpo.an1 --stderr=Microsoft-MIEngine-Error-yepcvpl1.vrt --pid=Microsoft-MIEngine-Pid-snc1b5ge.n2u --dbgExe=D:\MinGW\bin\gdb.exe --interpreter=mi
原字符串: 1234567
改变之后: 1654327
E:\Users\admin\Documents\VScode\Code> |