64,685
社区成员
发帖
与我相关
我的任务
分享
#include <iostream.h>
#include <fstream.h>
#include <string.h>
#define N 2
void swap(char *&a,char *&b)
{
char *t;
t=a;//strcpy(t,a);
a=b;//strcpy(a,b);
b=t;//strcpy(b,t);
}
void main()
{
int i;
char *e[2];
char *c[2];
e[0]="today";c[0]="今天";
e[1]="word";c[1]="单词";
int k=0;
cout<<e[0]<<" "<<c[0]<<endl;
cout<<e[1]<<" "<<c[1]<<endl;
if(strcmp(e[1],e[0])>0)
{
swap(e[0],e[1]);
swap(c[0],c[1]);
}
for(i=0;i <2;i++)
cout<<e[i]<<" "<<c[i]<<endl;
}
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
#define N 2
void swap(char *a,char *b)
{char *t;
strcpy(t,a);
strcpy(a,b);
strcpy(b,t);
}
int main()
{int j=0;
char *e[2];
char *c[2];
e[1]="today";c[1]="½ñÌì";
e[2]="word";c[2]="µ¥´Ê";
int k=0;
if(strcmp(e[1],e[2])>0) {swap(e[1],e[2]); swap(c[1],c[2]);}
//cout <<e[1] <<" " <<c[1] <<endl;
//cout <<e[2] <<" " <<c[2] <<endl;
for(j=1;j <=2;j++) //如果j从0开始,e[0]从何而来???j应该从1开始自增
cout <<e[j] <<" " <<c[j] <<endl;
return 0;
}