#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void GetArray(char *a[], int length)
{
int i;
printf("Please input:\n");
for (i = 0; i < length; i++)
{
a[i] = (char *)malloc(sizeof(char) * 64);
scanf("%s", a[i]);
}
}
void sort(char *a[], int length)
{
int i, j;
char *tmp;
for (i = 1; i < length - 1; i++)
{
for (j = 1; j < length - i - 1; j++)
{
//if (a[j + 1] < a[j])
if (strcmp(a[j + 1], a[j]) > 0)
{
tmp = a[j + 1];
a[j + 1] = a[j];
a[j] = tmp;
}
}
}
}
void print(char *a[], int length)
{
int i;
for (i = 1; i < length; i++)
{
printf("%s ", a[i]);
}
printf("\n");
}
int main(int argc, char *argv[])
{
int i, j, tmp;
//char *a[10] = {0};
int length = argc;
//GetArray(argv, length);
sort(argv, length);
print(argv, length);
return 0;
}
将字符串排序,main函数带参数
最新推荐文章于 2022-04-16 17:29:09 发布