有关于指针的用法,困扰好几天了··········
//在运用指针的过程中总是出问题,对字符串中复制、赋值时指针的用法有些不懂
#include<iostream.h>
#include<string.h>
char a[20],b[20];
int examine(char *p1,char *p2);
char sort(char *p);
void main()
{
cout<<"请输入需要破译的两个单词:"<<endl;
cin>>a>>b;
cout<<"examining..."<<endl;
int t=3;
char x,y;//[20][20]
x=sort(a);//strcpy(x,sort(*a));
y=sort(b);//strcpy(y,sort(*b));
t=examine(x,y);
if(t==0)
cout<<a<<"和"<<b<<"互为易位词"<<endl;
else
cout<<a<<"和"<<b<<"不是易位词"<<endl;
}
char sort(char *p)
{
char exch;
int i,j;
for(i=0;i<=20;i++)
for(j=i+1;j<=20;j++)
if(p[i]>p[j])
{
exch=p[i];p[i]=p[j];p[j]=exch;
}
return(*p);
}
int examine(char *p1,char *p2)
{
int sum=1;
if(strlen(p1)==strlen(p2))
{
int i=0,j=0;
for(i=0;i<=20;i++)
for(j=0;j<=20;j++)
{
if(p1[i]==p2[j])sum=0;
else sum=1;
}
}
return sum;
}
[解决办法]
char x,y;//[20][20]
t=examine(x,y);
int examine(char *p1,char *p2)
类型不对呀。
[解决办法]