解题思路:
注意事项:
参考代码:
#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 人评分
简单的a+b (C语言代码)浏览:816 |
【蟠桃记】 (C语言代码)浏览:1031 |
1128题解(返回值为数组的情况)浏览:473 |
简单的a+b (C语言代码)浏览:579 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:664 |
简单的a+b (C语言代码)浏览:466 |
拆分位数 (C语言代码)浏览:444 |
发工资咯 (C语言代码)浏览:792 |
C语言训练-求车速 (C语言代码)浏览:809 |
WU-玉龙学长买雪糕 (C++代码)浏览:1112 |