指针中字符串连接
#include<stdio.h>#include<stdlib.h>
int main()
{
char *s,*p;
s=(char *)malloc(20);
p="a boy";s="you are";
while(*s)s++;
while(*p)*s++=*p++;
*s='\0';
puts(s);
printf("\n");
free(s);
return 0;}
这是一个字符串连接的程序,可是不知怎么的,老是出错
程序代码:#include <stdio.h>
#include <stdlib.h>
int main()
{
char *s=(char *)malloc(20);
char *t=s; //这句比较重要,确保指针位于数组头部
char* p=" a boy.";
char* ss="You are";
while(*ss!='\0') *t++=*ss++;
while(*p!='\0') *t++=*p++;
*t='\0';
printf("%s\n",&s[0]);
free(s);
return 0;
}
