键盘输入一个字符串,插入到一个二维字符串数组a[6][10]={{"banana"},{"apple"},{"orange"},{"tea"},{"pear"}}中,然后对数组a进行排序并输出。
#include <string.h>
#include <stdio.h>
int main()
{
char a[6][10] = {{"banana"}, {"apple"}, {"orange"}, {"tea"}, {"pear"}};
char buf[10];
scanf("%s", a[5]);
for (int i = 0; i < 5; i++)
{
for (int j = i + 1; j < 6; j++)
{
if (strcmp(a[i], a[j]) > 0)
{
strcpy(buf, a[i]);
strcpy(a[i], a[j]);
strcpy(a[j], buf);
}
}
}
for (int j = 0; j < 6; j++)
printf("%s ", a[j]);
return 0;
}