#include "stdafx.h"
#includeiostream
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char s1[60]="kingbaby";
char *s2="hello";
int i=0;int j=0;
while(s1[i]!=' ')i++;
while((s1[i]=s2[j])!=' '){
j++;i++;
}
couts1endl;
return 0;
}
方法二
代码如下:
#include "stdafx.h"
#includeiostream
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char a[20] ="aaaa";
char b[10]="bbb";
char *stra=a;
char *strb=b;
while(*stra!=' ')stra++;
while(*strb!=' ')
{
*stra=*strb;//同时移动指针
strb++;
stra++;
}
return 0;
}