谁能帮忙写一个关于几个ARRY排列的程序,写出加分50

来源:百度知道 编辑:UC知道 时间:2024/09/21 21:45:03
例如:(输入是任意的,ARRAY结果是从小到大排列)
(输入) ABCDEGG
ABCDEFG
ABCDEEG
(得出) ABCDEEG
ABCDEFG
ABCDEGG

基本上就几个ARRAY的大小问题,问题是小弟我对地址方面,还有如何用STRNCMP搞不太清楚.
高手啊,但我们一定要用SWAP来做,还没有学qsort,拜托大虾了.还有是可以输入N个STRING,小弟菜鸟一个,但求过了这一科就彻底摆脱电脑拉.用C语言写
一楼的程序有问题啊,COMPILE不出来啊
2.c:13: error: 'for' loop initial declaration used outside C99 mode
2.c:14: error: 'for' loop initial declaration used outside C99 mode

#include <stdio.h>
#include <string.h>

inline void swap(char** lhs, char** rhs)
{
char* tmp = *lhs;
*lhs = *rhs;
*rhs = tmp;
}

void sort(char** base, int n)
{
for(int i = 0; i < n; ++i)
for(int j = n; j > i; --j)
if(strcmp(base[j], base[j-1]) < 0)
swap(&base[j], &base[j-1]);
}

#define N 3
#define SIZE 32

int main()
{
int i;
char *ptr[N];
char str[N][SIZE];

for(i = 0; i < N; ++i)
scanf("%s", ptr[i] = str[i]);

sort(ptr, N);

for(i = 0; i < N; ++i)
printf("%s ", ptr[i]);

return 0;
}