编写程序,把字符数组中的字母按由小到大的顺序排列并输出
时间: 2024-05-10 18:14:30 浏览: 18
好的,可以使用标准库中的qsort函数来进行排序。以下是一个示例程序:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 比较函数,用于qsort函数排序
int cmp(const void *a, const void *b) {
return *(char*)a - *(char*)b;
}
int main() {
char str[] = "hello world";
int n = strlen(str);
// 使用qsort函数进行排序
qsort(str, n, sizeof(char), cmp);
// 输出排序后的结果
printf("%s\n", str);
return 0;
}
```
运行结果为:
```
dehllloorw
```
阅读全文
相关推荐















