解题思路:
注意事项:
参考代码:
#include<stdio.h>
#include<string.h>
#define Long 3
int main()
{
void sort(char* p_c[]);
char* c[Long];
char** p_c = c; int i;
for (i=0; i<Long; i++)
c[i] = (char*)malloc(sizeof(char*) * 10);
for(p_c = c; p_c < c+Long;)
gets(*p_c++);
p_c = c;
sort(c);
for (i = 0; i < Long; i++)
printf("%s\n", *p_c++);
for (i = 0; i < Long; i++)
free(c[i]); //不加free耗时17,加了free耗时4
return 0;
}
void sort(char*p_c[])
{
int i, j;char *k;
for(i=0;i<Long-1;i++)
for(j=0;j<Long-i-1;j++)
if(strcmp(*(p_c+j), *(p_c+j+1))>0)
k= *(p_c + j), *(p_c + j)= *(p_c + j+1), *(p_c + j + 1)=k;
}
0.0分
2 人评分
C语言考试练习题_排列 (C++代码)浏览:647 |
K-进制数 (C++代码)浏览:880 |
简单的a+b (C语言代码)浏览:670 |
C语言程序设计教程(第三版)课后习题11.8 (C语言代码)浏览:629 |
A+B for Input-Output Practice (IV) (C++代码)浏览:694 |
剪刀石头布 (C语言代码)不知道怎么直接在scanf中用枚举变量浏览:1364 |
C语言训练-求1+2!+3!+...+N!的和 (C语言代码)浏览:791 |
WU-整数平均值 (C++代码)浏览:1267 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:511 |
【计算球体积】 (C语言代码)浏览:1129 |