把字符串复制到另一个指针中,程序怎么不能正确复制过去
#include<stdio.h>#include<stdlib.h>
int main(void)
{
char *p1;
char *p2;
p1 = (char *)malloc(sizeof(char));
p2 = (char *)malloc(sizeof(char[10]));
fgets(p1,11,stdin);
for (; *p1 != '\n'; p1++,p2++)
{
p2 = p1;
}
printf("p1:%s\np2:%s\n", p1,p2);
}