c语言编程问题(要用指针)请高手帮忙!!

来源:百度知道 编辑:UC知道 时间:2024/05/11 14:07:12
题目如下:
输入3个字符串,按由小到大的顺序输出。

必须应用指针方法处理!!

谢谢各位了

#include<stdio.h>
#include<string.h>
main()
{
char *str[3],*temp;
int i,j;
for(i=0;i<=2;i++)
str[i]=(char*)malloc(sizeof(char)*10);//申请内存
for(i=0;i<=2;i++)
{
gets(str[i]);
fflush(stdin);//读入
}
for(i=0;i<=1;i++)
for(j=0;j<=1;j++)
if(strcmp(str[j],str[j+1])>0)
{
temp=str[j];
str[j]=str[j+1];
str[j+1]=temp; //冒泡排序
}
for(i=0;i<=2;i++)
puts(str[i]); //输出
system("pause");
return 0;
}
字符串不超过10个字符
没有释放内存
我很缺分,给我吧

#include <stdio.h>

#define SIZE 10

#define Left(i) ((i) << 1)
#define Right(i) (((i) << 1) + 1)

void heapsort(int a[], int heapsize);
void maxheapify(int a[], int i, int heapsize);