LZ说的是字符串排序吧~~
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 100
void main()
{
char *str[MAX], *tmp;
int n, i, j;
tmp = (char*)malloc(MAX * sizeof(char));
printf ("\nHow many strings: ");
scanf ("%d", &n);
getchar ();
printf ("input the strings: \n");
for (i = 0; i < n; i++) {
printf ("%2d: ", i + 1);
str[i] = (char*)malloc(MAX * sizeof(char));
scanf ("%s", str[i]);
for (j = 0; j < i; j++)
if (strcmp(str[i], str[j]) < 0) {
strcpy (tmp, str[j]);
strcpy (str[j], str[i]);
strcpy (str[i], tmp);
}
}
free (tmp);
printf ("\nThe strings are: \n");
for (i = 0; i < n; i++) {
printf ("%2d: %s", i + 1, str[i]);
free(str[i]);
}
}
温馨提示:答案为网友推荐,仅供参考