首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

字符串互换有关问题

2012-04-19 
字符串互换问题C/C++ codevoid main(){char *name[]{az,bzz,gv,vf}int n4void mintomax(char

字符串互换问题

C/C++ code
void main(){    char *name[]={"az","bzz","gv","vf"};    int n=4;    void mintomax(char *p[],int a);    void output(char *p[],int a);    mintomax(name,n);    output(name,n);    system("pause");}void mintomax(char *p[],int a){        void trans(char *p[]);    int i,j;    char *temp;    for(j=0;j<a-2;j++)        for(i=j;i<a-1;i++)             if(strcmp(p[i],p[i+1])>0) trans(p[i],p[i+1]);        /*    {                temp=p[i];p[i]=p[i+1];p[i+1]=temp;            }*/    //用这个就OK。}void trans(char *x,char *y)    //我用这个函数数据调换为什么不行?{        char *temp;        temp=x;        x=y;        y=temp;}void output(char *p[],int a){    int i;    for(i=0;i<a;i++)        cout<<p[i]<<" ";    cout<<endl;}


[解决办法]
改成
C/C++ code
void trans(char *x,char *y)    //我用这个函数数据调换为什么不行?{        char *temp;        *temp=*x;        *x=*y;        *y=*temp;} 

热点排行
Bad Request.