c++指针,指针的指针,问题求教大神!
(1)#include<iostream>usingnamespacestd;intmain(){voidsort(char*name[],intn);voidprint...
(1)#include<iostream>
using namespace std;
int main()
{void sort(char *name[],int n);
void print(char *name[],int n);
char *name[5]={“england”,“usa”,“japan”,"china”,"thai”};
......
怎么改成键盘输出五个字符串?
(2)用指针的指针给输入的五个字符串排序,下面的程序错在哪里?
#include<iostream>
using namespace std;
int main()
{void sort(char **p);
int i;
char **p,*str[5],name[5];
cout<<"enter 5 strings:";
for(i=0;i<=4;i++)
cin>>name[i];
str[i]=&name[i];
p=str;
sort(p);
for(i=0;i<=4;i++)
cout<<str[i]<<" ";
cout<<endl;
system("pause");
return 0;
}
void sort(char **p)
{int i,j;
char *t;
for(i=0;i<=3;i++)
for(j=i+1;j<=4;j++)
if(strcmp(*(p+i),*(p+j))>0)
{t=*(p+i);*(p+i)=*(p+j);*(p+j)=t;}
} 展开
using namespace std;
int main()
{void sort(char *name[],int n);
void print(char *name[],int n);
char *name[5]={“england”,“usa”,“japan”,"china”,"thai”};
......
怎么改成键盘输出五个字符串?
(2)用指针的指针给输入的五个字符串排序,下面的程序错在哪里?
#include<iostream>
using namespace std;
int main()
{void sort(char **p);
int i;
char **p,*str[5],name[5];
cout<<"enter 5 strings:";
for(i=0;i<=4;i++)
cin>>name[i];
str[i]=&name[i];
p=str;
sort(p);
for(i=0;i<=4;i++)
cout<<str[i]<<" ";
cout<<endl;
system("pause");
return 0;
}
void sort(char **p)
{int i,j;
char *t;
for(i=0;i<=3;i++)
for(j=i+1;j<=4;j++)
if(strcmp(*(p+i),*(p+j))>0)
{t=*(p+i);*(p+i)=*(p+j);*(p+j)=t;}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询