字符串,高手来啊

来源:百度知道 编辑:UC知道 时间:2024/06/04 15:34:56
#include<iostream>
using namespace std;
int main()
{char a[3][20];
char *temp;
int i,j;
for(i=0;i<3;i++)
cin.getline(a[i],6,'/');
for(j=0;j<3;j++)
for(i=0;i<3-j-1;i++)
if(strcmp(a[i],a[i+1])>0)
{temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;}
for(i=0;i<3;i++)
cout<<a[i]<<endl;
return 0;
}怎么错了啊?

程序实现什么功能?

语法方面的问题:
1、temp定成char temp[20];
2、数据交换那里,因为用了行指针,要用strcpy函数
strcpy(temp,a[i]);
strcpy(a[i],a[i+1]);
strcpy(a[i+1],temp);