#include <stdio.h> #include <string.h> void fsort(char *color[ ], int n); int main(void ) { int i; char *pcolor[ ] = {"red", "blue", "yellow", "green", "black"}; void fsort(char *color[ ], int n); fsort(pcolor, 5); /* 调用函数 */ for(i = 0; i < 5; i++) printf("%s ", pcolor[i]); printf("\n"); return 0; } /* 请在这里填写答案 */
时间: 2024-01-12 11:05:37 浏览: 83
以下是完整代码和输出结果:
```c
#include <stdio.h>
#include <string.h>
void fsort(char *color[], int n);
int main(void) {
int i;
char *pcolor[] = {"red", "blue", "yellow", "green", "black"};
fsort(pcolor, 5); /* 调用函数 */
for (i = 0; i < 5; i++) {
printf("%s ", pcolor[i]);
}
printf("\n");
return 0;
}
void fsort(char *color[], int n) {
int i, j;
char *temp;
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n; j++) {
if (strcmp(color[i], color[j]) > 0) {
temp = color[i];
color[i] = color[j];
color[j] = temp;
}
}
}
}
```
输出结果:
```
black blue green red yellow
```
阅读全文