把两个字符串同时放进空数组里
#include <stdio.h>int main(){
char *s1="hello";
char *s2="world";
char s3[20];
int i,j=0;
for(i=0;i<20;i++){
s3[i]=*(s1+i);
if(s3[i]=='\0')
s3[i+1]=*(s2+j++);}
printf("%s\n",s3);
return 0;
}
2016-07-27 11:55
程序代码:#include <stdio.h>
int main() {
char *s1 = "hello";
char *s2 = "world";
char s3[20] = {0};
int i, j = 0;
for (i = 0; i<20; i++)
{
if (i < strlen(s1))
{
s3[i] = *(s1 + i);
}
else
{
s3[i] = *(s2 + j++);
}
}
printf("%s\n", s3);
return 0;
}
2016-07-27 12:09
程序代码:#include <stdio.h>
int main( void )
{
const char *s1 = "hello";
const char *s2 = "world";
char s3[20];
char* p3 = s3;
for( const char* p=s1; *p; *p3++=*p++ );
for( const char* p=s2; *p3++=*p++; );
puts( s3 );
return 0;
}
2016-07-27 12:27
2016-07-27 12:28
2016-07-27 15:24
程序代码:
#include <stdio.h>
int main() {
char *s1 = "hello";
char *s2 = "world";
char s3[20];
int i = 0;
while (i < 20 && s1[i] != '\0') {
s3[i] = s1[i];
++i;
}
int j = 0;
while (i < 20 && s2[j] != '\0') {
s3[i++] = s2[j++];
}
s3[i] = '\0';
printf("%s\n", s3);
return 0;
}

2016-07-27 20:05
2016-07-28 11:48