[此贴子已经被作者于2007-6-21 9:38:06编辑过]
3.
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
char *s1 = "abcdef", *s2 = "123456",*s3;
s3 =(char *) malloc(sizeof(char)*100);
strcpy(s1, s3);
strcat(s3, s2);
printf("\n%s\n",s3);
return 0;
}
最后应该能打印出你要求的s3.
malloc是动态分配内存
这么用纯属多余 而且用的也不对
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
char *s1 = "abcdef", *s2 = "123456", *s3;
s3 =(char *) malloc(sizeof(char)*(strlen(s1)+strlen(s2)));
strcpy(s3, s1);
strcat(s3, s2);
printf("%s\n", s3);
free(s3);
return 0;
}