如下程序用于对字符串按字母顺序由小到大排序后进行输出。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
int i, j;
char temp[9];
char str[][9] = {"Pascal", "Basic", "Fortran", "Java", "Visual C"};
for (i = 0; i <= 4; i++)
{
for (j = i + 1; j <= 5; j++)
{
if (strcmp(str[i], str[j]) > 0)
{
strcpy(temp, str[i]);
strcpy(str[i], str[j]);
strcpy(str[j], temp);
}
}
}
for (i = 0; i < 5; i++)
{
printf("%s\n", str[i]);
}
system("pause");
return 0;
}