解题思路:
注意事项:
参考代码:
#include <stdio.h> #include <stdlib.h> #include <string.h> int compare(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); //使用系统排序函数 } int main() { int n; char** words = malloc(n * sizeof(char*)); for (int i=0; i<3; i++) { words[i] = malloc(100 * sizeof(char)); scanf("%s", words[i]); } qsort(words, 3, sizeof(char*), compare); for (int i=0; i<3; i++) { printf("%s\n", words[i]); } for (int i=0; i<3; i++) { free(words[i]); // 释放每个单词占用的内存 } free(words); // 释放字符串指针数组占用的内存 return 0; }
0.0分
0 人评分
【密码】 (C语言代码)浏览:333 |
输出正反三角形 (C语言代码)浏览:786 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:1420 |
WU-蓝桥杯算法提高VIP-交换Easy (C++代码)浏览:1113 |
C语言程序设计教程(第三版)课后习题9.1 (C语言代码)浏览:681 |
最小公倍数 (C语言代码)浏览:1028 |
核桃的数量 (C语言代码)浏览:669 |
1124题解浏览:592 |
WU-C语言程序设计教程(第三版)课后习题12.3 (C++代码)浏览:855 |
P1002 (C++代码)浏览:713 |