题目:有三个字符串“Data structure”、“Computer design”、“C Progrom”,请按字符顺序输出这三个字符串(要求用指针数组指向这三个字符串)。
#include <stdio.h>
int main()
{
char* ar[3] = { "Data structure", "Computer design", "C Progrom" }, *temp;
int i,j;
for (i = 0; i < 3 - 1; i++)
{
for (j = 0; j < 3 - i - 1; j++)
if (strcmp(ar[j], ar[j + 1]) > 0)
{
temp = ar[j];
ar[j] = ar[j + 1];
ar[j + 1] = temp;
}
}
for (i = 0; i < 3; i++)
{
printf("%s\n\n", ar[i]);
}
return 0;
}