解题思路:
注意事项:
参考代码:
#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语言训练-计算t=1+1/2+1/3+...+1/n (C语言代码)浏览:908 |
WU-复数求和 (C++代码)浏览:2015 |
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:510 |
简单的a+b (C语言代码)浏览:505 |
JAM计数法 (C语言代码)浏览:671 |
小O的图案 (C语言代码)浏览:915 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:478 |
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:1200 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:631 |
C语言训练-百钱百鸡问题 (C语言代码)浏览:505 |