char * GetStr(int n)
{
int len=strlen("hello world ");
char *str=(char*)malloc((n*len+1)*sizeof(char));
str[0]='\0';
for(int i=0;i<n;i++)
{
strcat(str,"hello world ");
}
return str;
}
int main()
{
char *p1=GetStr(2);
char *p2=GetStr(3);
printf("%s,%s\n",p1,p2);
free(p1);
free(p2);
return 0;
}
动态内存。复制n个hello world
最新推荐文章于 2022-07-26 11:19:03 发布